Changeset 11278
- Timestamp:
- 08/12/14 16:41:56 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r11262 r11278 333 333 } 334 334 335 // this method works when called before the unsuccesful offspring are removed from the genealogy graph 336 // so it must always be called before RemoveUnsuccessfulOffspring() 335 337 private void ComputeSuccessRatios() { 336 const string successfulOffspringRatioTableHistoryName = "Successful offspring ratio"; 337 const string successfulOffspringRatioHeatMapName = "Successful offspring ratio heatmap"; 338 const string successfulOffspringRatioTableHistoryName = "Successful offspring ratios history"; 339 const string successfulOffspringAbsoluteValuesTableHistoryName = "Successful offspring values history"; 340 const string successfulOffspringRatioHeatMapName = "Successful offspring ratios heatmap"; 341 const string successfulOffspringValuesHeatMapName = "Successful offspring values heatmap"; 338 342 339 343 var population = PopulationParameter.ActualValue; … … 345 349 p.Weight++; 346 350 } 347 foreach (var v in GenealogyGraph.Ranks[generation - 1]) {348 if (v.OutDegree > 0)349 v.Weight /= v.OutDegree;350 }351 351 352 352 var results = ResultsParameter.ActualValue; 353 353 354 DataTableHistory history; 354 DataTableHistory successfulOffspringRatioHistory; 355 DataTableHistory successfulOffspringAbsoluteHistory; 355 356 if (!results.ContainsKey(successfulOffspringRatioTableHistoryName)) { 356 history = new DataTableHistory(); 357 results.Add(new Result(successfulOffspringRatioTableHistoryName, history)); 357 successfulOffspringRatioHistory = new DataTableHistory(); 358 successfulOffspringAbsoluteHistory = new DataTableHistory(); 359 results.Add(new Result(successfulOffspringRatioTableHistoryName, successfulOffspringRatioHistory)); 360 results.Add(new Result(successfulOffspringAbsoluteValuesTableHistoryName, successfulOffspringAbsoluteHistory)); 358 361 } else { 359 history = (DataTableHistory)results[successfulOffspringRatioTableHistoryName].Value; 360 } 361 var table = new DataTable(); 362 var row = new DataRow("Successful Offspring") { 362 successfulOffspringRatioHistory = (DataTableHistory)results[successfulOffspringRatioTableHistoryName].Value; 363 successfulOffspringAbsoluteHistory = (DataTableHistory)results[successfulOffspringAbsoluteValuesTableHistoryName].Value; 364 } 365 var successfulOffspringRatioTable = new DataTable(); 366 var successfulOffspringRatioRow = new DataRow("Successful Offspring Ratio") { VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true } }; 367 successfulOffspringRatioRow.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.OutDegree > 0 ? x.Weight / x.OutDegree : 0)); 368 successfulOffspringRatioTable.Rows.Add(successfulOffspringRatioRow); 369 successfulOffspringRatioHistory.Add(successfulOffspringRatioTable); 370 // create heatmap 371 double[,] ratios = new double[population.Length, successfulOffspringRatioHistory.Count]; 372 var ratiosHistoryList = successfulOffspringRatioHistory.AsReadOnly().ToList(); 373 for (int i = 0; i < ratiosHistoryList.Count; ++i) { 374 var values = ratiosHistoryList[i].Rows.First().Values; 375 for (int j = 0; j < values.Count; ++j) { 376 ratios[j, i] = values[j]; 377 } 378 } 379 var successfulOffspringRatios = new HeatMap(ratios); 380 if (!results.ContainsKey(successfulOffspringRatioHeatMapName)) { 381 results.Add(new Result(successfulOffspringRatioHeatMapName, successfulOffspringRatios)); 382 } else { 383 results[successfulOffspringRatioHeatMapName].Value = successfulOffspringRatios; 384 } 385 386 var successfulOffspringValuesTable = new DataTable(); 387 var successfulOffspringValuesRow = new DataRow("Successful Offspring Ratio") { 363 388 VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true } 364 389 }; 365 row.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.Weight)); 366 table.Rows.Add(row); 367 history.Add(table); 368 double[,] elements = new double[population.Length, history.Count]; 369 var col = history.AsReadOnly().ToList(); 370 for (int i = 0; i < col.Count; ++i) { 371 var values = col[i].Rows.First().Values; 390 successfulOffspringValuesRow.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.Weight)); 391 successfulOffspringValuesTable.Rows.Add(successfulOffspringValuesRow); 392 successfulOffspringAbsoluteHistory.Add(successfulOffspringValuesTable); 393 // create heatmap 394 double min = 0, max = 0; 395 double[,] elements = new double[population.Length, successfulOffspringAbsoluteHistory.Count]; 396 var absoluteHistoryList = successfulOffspringAbsoluteHistory.AsReadOnly().ToList(); 397 for (int i = 0; i < absoluteHistoryList.Count; ++i) { 398 var values = absoluteHistoryList[i].Rows.First().Values; 372 399 for (int j = 0; j < values.Count; ++j) { 373 400 elements[j, i] = values[j]; 374 } 375 } 376 401 if (max < values[j]) 402 max = values[j]; 403 if (min > values[j]) 404 min = values[j]; 405 } 406 } 377 407 var heatmap = new HeatMap(elements); 378 if (!results.ContainsKey(successfulOffspringRatioHeatMapName)) { 379 results.Add(new Result(successfulOffspringRatioHeatMapName, heatmap)); 408 heatmap.Maximum = max; 409 heatmap.Minimum = min; 410 if (!results.ContainsKey(successfulOffspringValuesHeatMapName)) { 411 results.Add(new Result(successfulOffspringValuesHeatMapName, heatmap)); 380 412 } else { 381 results[successfulOffspring RatioHeatMapName].Value = heatmap;413 results[successfulOffspringValuesHeatMapName].Value = heatmap; 382 414 } 383 415 }
Note: See TracChangeset
for help on using the changeset viewer.