/// <summary> /// Converts a List of configurations with its measured value (we take the non-functional property of the global state) into a a learning matrix. /// </summary> /// <param name="measurements">The configurations containing the measured values.</param> public void setLearningSet(List <Configuration> measurements) { double[] temparryLearn = new double[measurements.Count];; //measured values for (int i = 0; i < measurements.Count; i++) { this.learningSet.Add(measurements[i]); double val = 0; try { val = measurements[i].GetNFPValue(GlobalState.currentNFP); } catch (ArgumentException argEx) { GlobalState.logError.log(argEx.Message); val = measurements[i].GetNFPValue(); } temparryLearn[i] = val; } Y_learning = temparryLearn; Y_learning = Y_learning.T; //Now, we genrate for each inidividual option the data column. We also remove options from the initial feature set that occur in all or no variants of the learning set List <Feature> featuresToRemove = new List <Feature>(); foreach (Feature f in this.initialFeatures) { if (f.participatingNumOptions.Count > 0) { continue; } List <Feature> temp = new List <Feature>(); temp.Add(f); ILArray <double> column = createDataMatrix(temp); int nbSelections = 0; int nbDeselections = 0; for (int i = 0; i < column.Length; i++) { if (column[i] == 1) { nbSelections++; } if (column[i] == 0) { nbDeselections++; } if (nbSelections > 0 && nbDeselections > 0) { break; } } if (nbSelections == this.learningSet.Count) { featuresToRemove.Add(f); } if (nbDeselections == this.learningSet.Count) { featuresToRemove.Add(f); } } foreach (var f in featuresToRemove) { this.initialFeatures.Remove(f); } }
protected void readlog() { Dictionary<string, LinkedList<double>> d = log.Run(); List<string> list = new List<string>(d.Keys); //O1 = new ILArray<double>[0]; if (d.Keys.Count > 0) { foreach (string l in d.Keys) { O1 = new ILArray<double>[d[l].Count]; int i = 0; foreach (double db in d[l]) { O1[i] = db; i++; } //Task.Factory.StartNew(() => System.Console.WriteLine(ILNumerics.ILMath.fft(O1))); ILNumerics.ILRetArray<ILNumerics.complex> o; o = ILNumerics.ILMath.fft(O1); LinkedList<double> ds = extract_freq(o); double max = get_max(ds); double avg = average(ds); Console.WriteLine("LIST: "); //print_list(ds); Console.WriteLine("max: " + max + " avg: " + avg); if (max - avg > 13000) { Task task = new Task(new Action(() => level.ship.Accerlerate())); task.Start(); task.Wait(2000); } //Console.Write("list is: "); //Task.Factory.StartNew(() => print_list(ds)); } } }
private void OnTimedEventData(object source, ElapsedEventArgs e) { ILNumerics.ILRetArray<ILNumerics.complex> o = ILNumerics.ILMath.fft(O1); if (O1.IsEmpty) { return; } LinkedList<double> ds = extract_freq(o); //print_list(ds); Task.Factory.StartNew(() => plot(ds)); int move = scan_list(ds); switch(move){ case 1: level.ship.Accerlerate(); break; case 2: level.ShipShoot(); break; case 3: level.ship.RotateShipLeft(90); break; case 4: level.ship.RotateShipRight(90); break; default: break; } O1 = new ILArray<double>[2000]; O1_count = 0; }
protected override void Initialize() { freeCam = false; currentCamera = 1; lev = 0; graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 480; up_color = Color.Black; down_color = Color.Black; left_color = Color.Black; right_color = Color.Black; log = new EEG_Logger(); Task.Factory.StartNew(() => start_timers()); O1 = new ILArray<double>[2001]; O1_count = 0; base.Initialize(); nocounts = 0; }