Created
January 7, 2016 23:19
-
-
Save Uinelj/440cecd2c5533abbf397 to your computer and use it in GitHub Desktop.
prediction dégueu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rand; | |
use rand::Rng; | |
use std::io; | |
fn main() { | |
//let chains = vec!['a', 'b']; | |
let mut values= vec![vec![0.1, 0.3, 0.6], vec![0.2, 0.2, 0.6], vec![0.1, 0.1, 0.8]]; | |
let genre = vec!["Rock", "Pop", "Techno"]; | |
let mut startingNode = 0; | |
let mut currentNode = 0; | |
let mut feedback = String::new(); | |
//println!("{:?}", values); | |
//println!("StartingNode : {:?} NextNode : {:?}", startingNode, get_next_node(0, values)); | |
println!("{:?}", values[0][1]); | |
for i in 0..100 { | |
println!("->{:?}", genre[startingNode as usize]); | |
startingNode = get_next_node(startingNode as usize, &values); | |
} | |
loop { | |
//println!("Genre precedent : {:?}", genre[startingNode as usize]); | |
println!("{:?}", values); | |
currentNode = get_next_node(startingNode as usize, &values); | |
println!("Genre a l'ecoute : {:?} Tu aimes ?", genre[currentNode as usize]); | |
io::stdin().read_line(&mut feedback) | |
.ok() | |
.expect("Failed"); | |
apply_feedback(&feedback, 0.1, &mut values, startingNode as usize, currentNode as usize); | |
startingNode = currentNode; | |
} | |
println!("{:?}", values[0][1]); | |
// let mut vek = vec![1, 2, 3, 4]; | |
// println!("{:?}", vek); | |
// println!("Vector length {:?}", vek.len()); | |
// for i in 1..vek.len() { | |
// vek.push(i); | |
// } | |
// println!("{:?}", vek); | |
// println!("Hello, world!"); | |
} | |
fn get_nodes_number(values: Vec<Vec<f32>>) -> usize { | |
values.len() | |
} | |
fn get_next_node(actualNode : usize, values : &Vec<Vec<f32>>) -> u32 { | |
let mut random = rand::thread_rng().gen_range(0f32, 1.); | |
for i in 0..values.len() { | |
//println!("Random : {:?} and values : {:?}", random, values[actualNode][i]); | |
if random < values[actualNode][i] { | |
return i as u32; | |
}else{ | |
random -= values[actualNode][i]; | |
} | |
} | |
return 1; | |
} | |
fn apply_feedback(feedback: &String, sensibility : f32, values: &mut Vec<Vec<f32>>, startingNode : usize, endingNode : usize) { | |
//println!("{:?}", feedback as f32 * sensibility); | |
//TODO: Resultats bizarres quand on soustrait. | |
let signedSensibility = | |
if feedback == "non" { | |
sensibility * (-1.0) | |
} else { | |
sensibility | |
}; | |
values[startingNode][endingNode] += signedSensibility; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment