static Tuple2 <int> GetDataWindowOffsetAndSize(int count, Chromosome chrom) { int offset = MathEx.Clamp(0, count - 1, (int)(chrom.TrainingOffsetPct * count)); int size = MathEx.Clamp(1, count - offset, (int)(chrom.TrainingSizePct * count)); return(Tuple2.Create(offset, size)); }
public static Tuple2 <T> SelectTwoAccordingToQuality <T>(IList <T> items, Func <T, double> quality) { var possibleFirsts = items; var first = SelectOneAccordingToQuality(possibleFirsts, quality); var possibleSeconds = items.Except(Lists.Create(first)).ToList(); var second = SelectOneAccordingToQuality(possibleSeconds, quality); return(Tuple2.Create(first, second)); }
internal static Tuple2 <Chromosome> CrossOverChromosomes(Chromosome a, Chromosome b) { Debug.Assert(a.NetworkType == b.NetworkType); Debug.Assert(a.OrderInMixture == b.OrderInMixture); Func <Gene, Gene, Tuple2 <Gene> > crossGenes = (x, y) => { Debug.Assert(x.Name == y.Name); return(QuqeUtil.WithProb(0.5) ? Tuple2.Create(x, y) : Tuple2.Create(y, x)); }; return(CrossOver(a.Genes, b.Genes, crossGenes, genes => new Chromosome(a.NetworkType, genes, a.OrderInMixture))); }