private void ChangeExplorerPositions(int i) { KnowlegeBaseSARules temp = new KnowlegeBaseSARules(); temp = ExplorerParticles[i]; for (int k = 0; k < temp.TermsSet.Count; k++) { for (int j = 0; j < temp.TermsSet[k].Parametrs.Length; j++) { temp.TermsSet[k].Parametrs[j] += VelocityVector.TermsSet[k].Parametrs[j]; } } if (result.approxLearnSamples(ExplorerParticles[i]) < result.approxLearnSamples(ParticlesBest[ExplorerParticles[i]])) { ParticlesBest.Remove(ExplorerParticles[i]); ParticlesBest.Add(temp, ExplorerParticles[i]); } else { KnowlegeBaseSARules tmp = new KnowlegeBaseSARules(); tmp = ParticlesBest[ExplorerParticles[i]]; ParticlesBest.Remove(ExplorerParticles[i]); ParticlesBest.Add(temp, tmp); } ExplorerParticles[i] = temp; }
private void calculateVLL(KnowlegeBaseSARules Explorer, KnowlegeBaseSARules ExplorerBestPosition, int index) { KnowlegeBaseSARules part1 = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); KnowlegeBaseSARules part2 = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); for (int i = 0; i < part1.TermsSet.Count; i++) { for (int j = 0; j < part1.TermsSet[i].Parametrs.Length; j++) { part1.TermsSet[i].Parametrs[j] = (ExplorerBestPosition.TermsSet[i].Parametrs[j] - Explorer.TermsSet[i].Parametrs[j]) * ALocal * rand.NextDouble(); } } for (int i = 0; i < part2.TermsSet.Count; i++) { for (int j = 0; j < part2.TermsSet[i].Parametrs.Length; j++) { part2.TermsSet[i].Parametrs[j] = (LocalLeaders[index].TermsSet[i].Parametrs[j] - Explorer.TermsSet[i].Parametrs[j]) * BLocal * rand.NextDouble(); } } for (int i = 0; i < VelocityVectorLL.TermsSet.Count; i++) { for (int j = 0; j < VelocityVectorLL.TermsSet[i].Parametrs.Length; j++) { VelocityVectorLL.TermsSet[i].Parametrs[j] = (part1.TermsSet[i].Parametrs[j] + part2.TermsSet[i].Parametrs[j]); } } }
public virtual void Init(ILearnAlgorithmConf conf) { currentConf = conf as GeneticConf; fullFuzzySystem = result; step = 0; errorAfter = 0; errorBefore = result.approxLearnSamples(result.RulesDatabaseSet[0]); backUp = result.RulesDatabaseSet[0]; initFunc = new initFuncType(localInit); if (currentConf.GENCTypeInit == GeneticConf.Alg_Init_Type.Глобальный) { initFunc = new initFuncType(globalInit); } crossoverFunc = new crossoverFuncType(unifiedCrossover); if (currentConf.GENCTypeCrossover == GeneticConf.Alg_Crossover_Type.Многоточечный) { crossoverFunc = new crossoverFuncType(pointsCrossover); } selectionFunc = new selectionFuncType(rouletteSelection); if (currentConf.GENCTypeSelection == GeneticConf.Alg_Selection_Type.Случайный) { selectionFunc = new selectionFuncType(randomSelection); } if (currentConf.GENCTypeSelection == GeneticConf.Alg_Selection_Type.Элитарный) { selectionFunc = new selectionFuncType(eliteSelection); } fullInit(); // Здесь проходит инициализация }
public override SAFuzzySystem TuneUpFuzzySystem(SAFuzzySystem Approximate, ILearnAlgorithmConf conf) { BacteryAlgorithmConfig Config = conf as BacteryAlgorithmConfig; sendBactery = Config.BFOCountSolution; interPSOtoSend = Config.BFOCountIteration; result = Approximate; if (result.RulesDatabaseSet.Count < 1) { throw new InvalidDataException("Нечеткая система не проинициализированна"); } KnowlegeBaseSARules backSave = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); double backResult = result.approxLearnSamples(result.RulesDatabaseSet[0]); savetoUFS(result.RulesDatabaseSet, 0, 0, 0); BacteryRunner(); KnowlegeBaseSARules[] solutions = loadDatabase(); solutions = sortSolution(solutions); if (solutions.Count() < 1) { result.RulesDatabaseSet[0] = backSave; return(result); } result.RulesDatabaseSet[0] = solutions[0]; double newResult = result.approxLearnSamples(result.RulesDatabaseSet[0]); if (newResult > backResult) { result.RulesDatabaseSet[0] = backSave; } result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }
private int findNearestLocalLeader(KnowlegeBaseSARules Explorer) { int index = 0; double minimum = 999999999999; for (int k = 0; k < numberOfLocalLeaders; k++) { double distance = 0; for (int i = 0; i < LocalLeaders[k].TermsSet.Count; i++) { for (int j = 0; j < numberOfParametrs; j++) { distance += Math.Pow(Explorer.TermsSet[i].Parametrs[j] - LocalLeaders[k].TermsSet[i].Parametrs[j], 2); } } //for (int i = 0; i < Explorer.RulesDatabase.Count; i++) //{ // distance += Math.Pow(Explorer.RulesDatabase[i].Cons_DoubleOutput - LocalLeaders[k].RulesDatabase[i].Cons_DoubleOutput, 2); //} distance = Math.Sqrt(distance); if (distance < minimum) { minimum = distance; index = k; } } return(index); }
private void SetPopulation() { Population = new KnowlegeBaseSARules[numberOfAllParts]; KnowlegeBaseSARules TempRule = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); Population[0] = TempRule; Universal = TempRule; for (int i = 1; i < numberOfAllParts; i++) { Population[i] = new KnowlegeBaseSARules(TempRule); for (int j = 0; j < Population[i].TermsSet.Count; j++) { for (int k = 0; k < Population[i].TermsSet[j].Parametrs.Length; k++) { Population[i].TermsSet[j].Parametrs[k] = GaussRandom.Random_gaussian(rand, Population[i].TermsSet[j].Parametrs[k], 0.1 * Population[i].TermsSet[j].Parametrs[k]); } } result.UnlaidProtectionFix(Population[i]); } Universal = new KnowlegeBaseSARules(TempRule); for (int i = 0; i < Universal.TermsSet.Count; i++) { Population[i] = new KnowlegeBaseSARules(TempRule); for (int j = 0; j < Universal.TermsSet[i].Parametrs.Length; j++) { Universal.TermsSet[i].Parametrs[j] = GaussRandom.Random_gaussian(rand, Universal.TermsSet[i].Parametrs[j], 0.1 * Universal.TermsSet[i].Parametrs[j]); } } }
KnowlegeBaseSARules unifiedCrossover(KnowlegeBaseSARules parent1, KnowlegeBaseSARules parent2) { double b = (currentConf.GENCPopabilityCrossover / 100); KnowlegeBaseSARules child; child = new KnowlegeBaseSARules(parent1); for (int i = 0; i < parent1.TermsSet.Count; i++) //Parallel.For(0, parent1.TermsSet.Count, i => { if (b > allRandom.NextDouble()) { child.TermsSet[i].Parametrs = parent2.TermsSet[i].Parametrs; } //}); } double[] tempMassiveCh = child.all_conq_of_rules.Clone() as double[]; double[] tempMassiveP2 = parent2.all_conq_of_rules.Clone() as double[]; for (int i = 0; i < tempMassiveCh.Count(); i++) //Parallel.For(0, parent1.all_conq_of_rules.Count(), i => { if (b > allRandom.NextDouble()) { tempMassiveCh[i] = tempMassiveP2[i]; } } child.all_conq_of_rules = tempMassiveCh; //}); return(child); }
protected void EvalXi(double[][] X, double[] Y, KnowlegeBaseSARules knowlegeBaseA) { EvalDividerXi(X, Y, knowlegeBaseA); // foreach dataVector in dataSet for (int s = 0; s < Y.Length; s++) { double[] x = X[s]; // result.Learn_Samples_set.Data_Rows[s].Input_Attribute_Value; // foreach rule in base.rules for (int k = 0; k < R; k++) { double mul = 1; // foreach term in rule.terms foreach (Term term in knowlegeBaseA.RulesDatabase[k].ListTermsInRule) { mul *= term.LevelOfMembership(x); if (Math.Abs(mul - 0) < EPSILON) { break; } } xiValue[s][k] = mul / dividerXi[s]; } } }
public OutLookersBeeParams(KnowlegeBaseSARules theSource, KnowlegeBaseSARules Best, BeeParamsAlgorithm parrent, Random rand) : base(theSource, parrent) { for (int i = 0; i < PositionOfBee.TermsSet.Count; i++) { double [] Params = PositionOfBee.TermsSet[i].Parametrs; for (int j = 0; j < Params.Count(); j++) { int Choose = rand.Next(2); switch (Choose) { case 0: { Params[j] = Best.TermsSet[i].Parametrs[j] + Math.Abs(Best.TermsSet[i].Parametrs[j] - Params[j]) * rand.NextDouble(); } break; case 1: { Params[j] = Best.TermsSet[i].Parametrs[j] - Math.Abs(Best.TermsSet[i].Parametrs[j] - Params[j]) * rand.NextDouble(); } break; } } PositionOfBee.TermsSet[i].Parametrs = Params; } double[] consq = PositionOfBee.all_conq_of_rules; for (int i = 0; i < consq[i]; i++) { int choose = rand.Next(2); switch (choose) { case 0: { consq[i] = Best.all_conq_of_rules[i] + Math.Abs(Best.all_conq_of_rules[i] - consq[i]) * rand.NextDouble(); } break; case 1: { consq[i] = Best.all_conq_of_rules[i] - Math.Abs(Best.all_conq_of_rules[i] - consq[i]) * rand.NextDouble(); } break; } } PositionOfBee.all_conq_of_rules = consq; getGoodsImproove(); }
public void GetDots(SAFuzzySystem approx, KnowlegeBaseSARules knowlegeBase) { // Dots (COMPLETE, BUT DOUBLECHECK WHEN DEBUGGING) var inputs = approx.LearnSamplesSet.DataRows.AsParallel().AsOrdered() .Select(dataRow => dataRow.InputAttributeValue).ToList(); var localDots = inputs.AsParallel().AsOrdered() .Where(InBetweenTheLimits).ToList(); // var strs = new List<string[]>(localDots.Count); // for (int i = 0; i < strs.Capacity; i++) // strs.Add(new[] { string.Empty }); var rezs = approx.LearnSamplesSet.DataRows.AsParallel().AsOrdered() .Where(row => localDots.Contains(row.InputAttributeValue)) .Select(dataRow => dataRow.DoubleOutput).ToList(); List <SampleSet.RowSample> rows = localDots.Select((t, i) => new SampleSet.RowSample(t, null, rezs[i], null)).ToList(); var samples = new SampleSet("1.dat", rows, approx.LearnSamplesSet.InputAttributes, approx.LearnSamplesSet.OutputAttribute); system = new SAFuzzySystem(samples, samples); var usedRules = GetRules(knowlegeBase); system.RulesDatabaseSet.Add(new KnowlegeBaseSARules(knowlegeBase, null)); }
public HiveParams(BeeParamsAlgorithm Parrent, KnowlegeBaseSARules Best) { theParrent = Parrent; hostArchive = new List <BeeParams>(); hostArchive.Add(new BeeParams(Best, Parrent)); hostArchive[0].getGoodsImproove(); }
//нахождение расстояния ощущения (соседства) private List <int> countneihbors(KnowlegeBaseSARules x) { double border = distneihbor(x); List <int> neihbors = new List <int>(); /* * //вывод значение дистанции соседа * for (int g = 0; g < Population.Length; g++) * { * Console.Write("Знаение distneihbor = "); * Console.WriteLine(distneihbor(x)); * } */ for (int j = 0; j < Population.Length; j++) { if (x != Population[j]) { if (Distance(x, Population[j]) < border) { neihbors.Add(j); } } } return(neihbors); }
//нахождение расстояния ощущения (соседства) private double distneihbor(KnowlegeBaseSARules x) { double sum = 0, dneihbor; for (int j = 0; j < Population.Length; j++) { if (x != Population[j]) { sum += Distance(x, Population[j]); } /* #if debug * //вывод значение суммы расстояний между переменными * Console.Write("Значение суммы для расчета расстояния ощущения = "); * Console.WriteLine(sum); #endif */ } dneihbor = sum * (1.0 / (1.5 * Population.Length)); /* * //вывод значение dneihbor соседей * Console.Write("Значение dneihbor для расчета расстояния ощущения = "); * Console.WriteLine(dneihbor); */ return(dneihbor); }
//нахождение расстояния между крилями private double Distance(KnowlegeBaseSARules x, KnowlegeBaseSARules y) { double dist, sum = 0; for (int i = 0; i < x.TermsSet.Count; i++) { for (int j = 0; j < x.TermsSet[i].Parametrs.Length; j++) { sum += Math.Pow(x.TermsSet[i].Parametrs[j] - y.TermsSet[i].Parametrs[j], 2); } } for (int i = 0; i < x.RulesDatabase.Count; i++) { sum += Math.Pow(x.RulesDatabase[i].IndependentConstantConsequent - y.RulesDatabase[i].IndependentConstantConsequent, 2); } dist = Math.Sqrt(sum); /* #if debug * //вывод значение dist соседа * Console.Write("Значение dist = "); * Console.WriteLine(dist); #endif */ return(dist); }
private SAFuzzySystem BreakCrossTerm(SAFuzzySystem Approx, int Feature, int indexATerm, int indexBterm, int dataBase) { SAFuzzySystem result = Approx; KnowlegeBaseSARules DataSet = result.RulesDatabaseSet[dataBase]; List <Term> soureTerms = DataSet.TermsSet.Where(x => x.NumVar == Feature).ToList(); Term ATerm = soureTerms[indexATerm]; Term BTerm = soureTerms[indexBterm]; Term Left = ATerm; Term Right = BTerm; if (ATerm.Pick > BTerm.Pick) { Left = BTerm; Right = ATerm; } double border = (Left.Max + Right.Min) / 2; Left.Max = border; Right.Min = border; result.RulesDatabaseSet[dataBase] = DataSet; return(result); }
public override SAFuzzySystem TuneUpFuzzySystem(SAFuzzySystem Classifier, ILearnAlgorithmConf conf) { Init(conf); KnowlegeBaseSARules temp_c_Rule = new KnowlegeBaseSARules(Classifier.RulesDatabaseSet[0]); SAFuzzySystem result = Classifier; for (int t = 0; t < population_count; t++) { monkey[t] = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); for (int k = 0; k < result.RulesDatabaseSet[0].TermsSet.Count; k++) { for (int q = 0; q < result.RulesDatabaseSet[0].TermsSet[k].CountParams; q++) { //monkey[t].TermsSet[k].Parametrs[q] = StaticRandom.NextDouble() * (result.RulesDatabaseSet[0].TermsSet[k].Max - result.RulesDatabaseSet[0].TermsSet[k].Min); monkey[t].TermsSet[k].Parametrs[q] = GaussRandom.Random_gaussian(rand, monkey[t].TermsSet[k].Parametrs[q], monkey[t].TermsSet[k].Parametrs[q] * 0.05); } } result.UnlaidProtectionFix(monkey[t]); // delete testvals[t] = result.ErrorLearnSamples(monkey[t]); Console.WriteLine("Begin: " + t.ToString() + " " + iter.ToString() + " " + testvals[t].ToString()); } bestsolution = new KnowlegeBaseSARules(monkey.SelectBest(result, 1)[0]); bestsolutionnumber = result.ErrorLearnSamples(bestsolution); iter_amount = somersault_iter * (1 + jump_iter * (1 + crawl_iter)); deltaLength = result.RulesDatabaseSet[0].TermsSet.Sum(x => x.Parametrs.Length); for (int r = 0; r < somersault_iter; r++) { for (int t = 0; t < jump_iter; t++) { for (int e = 0; e < crawl_iter; e++) { iter++; CheckForBest(result); oneClimb(result, deltaLength, step); //Console.WriteLine(iter_amount.ToString() + "/" + iter.ToString()); } iter++; oneWatchJump(result); //Console.WriteLine(iter_amount.ToString() + "/" + iter.ToString()); } iter++; oneGlobalJump(result); Console.WriteLine(iter_amount.ToString() + "/" + iter.ToString()); } /* for (int t = 0; t < population_count; t++) * if (result.ErrorLearnSamples(monkey[best]) < result.ErrorLearnSamples(monkey[t])) * best = t; */ CheckForBest(result); if (bestsolutionnumber < result.ErrorLearnSamples(result.RulesDatabaseSet[0])) { result.RulesDatabaseSet[0] = bestsolution; } iter = 0; return(result); }
public static void Inject(this KnowlegeBaseSARules[] Destination, int indexStartDestination, KnowlegeBaseSARules[] Source, int indexStartSource, int CountIjected, SAFuzzySystem Approx) { Destination = Destination.SortRules(Approx); for (int i = 0; i < CountIjected; i++) { Destination[i + indexStartDestination] = new KnowlegeBaseSARules(Source[i + indexStartSource]); } }
public override SAFuzzySystem Generate(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, IGeneratorConf config) { start_add_rules = Approximate.RulesDatabaseSet.Count; SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { AbstractNotSafeGenerator tempGen = new GeneratorRulesEveryoneWithEveryone(); result = tempGen.Generate(result, config); GC.Collect(); } Request_count_rules = ((RullesShrinkConf)config).RSCCountRules; max_count_rules = ((RullesShrinkConf)config).RSCMaxRules; count_slices = ((RullesShrinkConf)config).IEWECountSlice; min_count_rules = ((RullesShrinkConf)config).RSCMinRules; type_term = ((RullesShrinkConf)config).IEWEFuncType; int count_of_swith_off = ((RullesShrinkConf)config).RSCMaxRules - Request_count_rules; List <byte> Varians_of_run_system = new List <byte>(); for (int i = 0; i < Approximate.RulesDatabaseSet[0].RulesDatabase.Count; i++) { Varians_of_run_system.Add(1); } for (int i = 0; i < count_of_swith_off; i++) { Varians_of_run_system[i] = 0; } Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { KnowlegeBaseSARules temp_rules = new KnowlegeBaseSARules(result.RulesDatabaseSet[0], Pull_of_systems[i]); temp_rules.TrimTerms(); result.RulesDatabaseSet.Add(temp_rules); result.UnlaidProtectionFix(result.RulesDatabaseSet[start_add_rules + i]); errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[start_add_rules + i])); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); KnowlegeBaseSARules best = result.RulesDatabaseSet[start_add_rules + best_index]; result.RulesDatabaseSet.Clear(); result.RulesDatabaseSet.Add(best); Console.WriteLine(Pull_of_systems.Count()); GC.Collect(); // result.UnlaidProtectionFix(); result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }
public new static List <BeeParams> FlyScout(int countofBee, Random rand, KnowlegeBaseSARules Source, BeeParamsAlgorithm parrent) { List <BeeParams> result = new List <BeeParams>(); Parallel.For(0, countofBee, (int i) => { result.Add(new ScoutParams(Source, parrent, rand)); }); return(result); }
public static List <BeeParams> FlyScout(int countofBee, Random rand, KnowlegeBaseSARules Source, BeeParamsAlgorithm parrent) { List <BeeParams> result = new List <BeeParams>(); for (int i = 0; i < countofBee; i++) { result.Add(new ScoutParams(Source, parrent, rand)); } return(result); }
public virtual void WJVector_gen(int j) { WJVector = new KnowlegeBaseSARules(monkey[j]); for (int k = 0; k < monkey[j].TermsSet.Count; k++) { for (int q = 0; q < monkey[j].TermsSet[k].CountParams; q++) { WJVector.TermsSet[k].Parametrs[q] += 2 * (StaticRandom.NextDouble() - 0.5) * watch_jump_parameter; } } }
private SAFuzzySystem UniTerm(SAFuzzySystem Approx, int Feature, int indexATerm, int indexBterm, int dataBase) { SAFuzzySystem result = Approx; KnowlegeBaseSARules DataSet = result.RulesDatabaseSet[dataBase]; List <Term> soureTerms = DataSet.TermsSet.Where(x => x.NumVar == Feature).ToList(); Term ATerm = soureTerms[indexATerm]; Term BTerm = soureTerms[indexBterm]; double newPick = (ATerm.Pick + BTerm.Pick) / 2; double newMin = ATerm.Min; if (BTerm.Min < newMin) { newMin = BTerm.Min; } double newMax = ATerm.Max; if (BTerm.Max > newMax) { newMax = BTerm.Max; } Term uniTerm = new Term(ATerm); uniTerm.Pick = newPick; uniTerm.Min = newMin; uniTerm.Max = newMax; DataSet.TermsSet.Add(uniTerm); List <SARule> toChangeArules = DataSet.RulesDatabase.Where(x => x.ListTermsInRule.Contains(ATerm)).ToList(); for (int i = 0; i < toChangeArules.Count(); i++) { int indexofA = toChangeArules[i].ListTermsInRule.IndexOf(ATerm); toChangeArules[i].ListTermsInRule[indexofA] = uniTerm; } DataSet.TermsSet.Remove(ATerm); List <SARule> toChangeBrules = DataSet.RulesDatabase.Where(x => x.ListTermsInRule.Contains(BTerm)).ToList(); for (int i = 0; i < toChangeBrules.Count(); i++) { int indexofB = toChangeBrules[i].ListTermsInRule.IndexOf(BTerm); toChangeBrules[i].ListTermsInRule[indexofB] = uniTerm; } DataSet.TermsSet.Remove(BTerm); result.RulesDatabaseSet[dataBase] = DataSet; return(result); }
public virtual void oneIterate(SAFuzzySystem result) { for (int j = 0; j < count_particle; j++) { w = 1 / (1 + Math.Exp(-(Errors[j] - OldErrors[j]) / 0.01)); for (int k = 0; k < X[j].TermsSet.Count; k++) { for (int q = 0; q < X[j].TermsSet[k].CountParams; q++) { double bp = Pi[j].TermsSet[k].Parametrs[q]; V[j].TermsSet[k].Parametrs[q] = V[j].TermsSet[k].Parametrs[q] * w + c1 * rnd.NextDouble() * (bp - X[j].TermsSet[k].Parametrs[q]) + c2 * rnd.NextDouble() * (Pg.TermsSet[k].Parametrs[q] - X[j].TermsSet[k].Parametrs[q]); X[j].TermsSet[k].Parametrs[q] += V[j].TermsSet[k].Parametrs[q]; } } double[] bf = new double[V[j].all_conq_of_rules.Length]; double[] bfw = new double[V[j].all_conq_of_rules.Length]; for (int k = 0; k < V[j].all_conq_of_rules.Length; k++) { bfw[k] = V[j].all_conq_of_rules[k] * w + c1 * rnd.NextDouble() * (Pi[j].all_conq_of_rules[k] - X[j].all_conq_of_rules[k]) + c2 * rnd.NextDouble() * (Pg.all_conq_of_rules[k] - X[j].all_conq_of_rules[k]); double sw = X[j].all_conq_of_rules[k] + bfw[k]; bf[k] = sw; } X[j].all_conq_of_rules = bf; V[j].all_conq_of_rules = bfw; double newError = 0; result.RulesDatabaseSet.Add(X[j]); int temp_index = result.RulesDatabaseSet.Count - 1; bool success = true; try { newError = result.approxLearnSamples(result.RulesDatabaseSet[temp_index]); } catch (Exception) { success = false; } result.RulesDatabaseSet.RemoveAt(temp_index); if (success && (newError < Errors[j])) { OldErrors[j] = Errors[j]; Errors[j] = newError; Pi[j] = new KnowlegeBaseSARules(X[j]); } if (minError > newError) { minError = newError; Pg = new KnowlegeBaseSARules(X[j]); } } }
public virtual void CheckForBest(SAFuzzySystem result) { KnowlegeBaseSARules temp = monkey.SelectBest(result, 1)[0]; double tempnumber = result.ErrorLearnSamples(temp); if (bestsolutionnumber > tempnumber) { bestsolution = new KnowlegeBaseSARules(temp); bestsolutionnumber = tempnumber; // delete // Console.WriteLine("NEWBEST " + bestsolutionnumber); } }
private void ChangeAimlessPosition(KnowlegeBaseSARules Aimless) { KnowlegeBaseSARules GlobalRand = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); SSVector_gen(); for (int i = 0; i < Aimless.TermsSet.Count; i++) { for (int j = 0; j < Aimless.TermsSet[i].Parametrs.Length; j++) { Aimless.TermsSet[i].Parametrs[j] = ((rand.NextDouble() + 0.5) * (SSVector.TermsSet[i].Parametrs[j])); } } }
// дописываю public static int sign(KnowlegeBaseSARules monkeysum, KnowlegeBaseSARules monkeysub, double num, SAFuzzySystem result) { double f1 = ((result.ErrorLearnSamples(monkeysum) - result.ErrorLearnSamples(monkeysub))) / 2 * num; if (f1 < 0) { return(1); } else { return(-1); } }
public override SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf config) { theFuzzySystem = Approximate; if (theFuzzySystem.RulesDatabaseSet.Count == 0) { throw new System.FormatException("Что то не то с входными данными"); } OptimizeTermShrinkHardCoreConf Config = config as OptimizeTermShrinkHardCoreConf; count_shrink = Config.OTSHCCountShrinkTerm; for (int i = 0; i < Approximate.CountFeatures; i++) { int count_terms_for_var = Approximate.RulesDatabaseSet[0].TermsSet.FindAll(x => x.NumVar == i).Count; if (count_terms_for_var >= count_shrink) { int shrinkcounter = count_shrink; List <int> Varians_of_cut = new List <int>(); for (int j = 0; j < count_terms_for_var; j++) { if (shrinkcounter > 0) { Varians_of_cut.Add(0); } else { Varians_of_cut.Add(1); } shrinkcounter--; } Generate_all_variant_in_pool(Varians_of_cut); for (int j = 0; j < Pull_of_systems.Count; j++) { KnowlegeBaseSARules current = MakeCut(Approximate.RulesDatabaseSet[0], Pull_of_systems[j], i); Systems_ready_to_test.Add(current); errors_of_systems.Add(theFuzzySystem.approxLearnSamples(current)); } Pull_of_systems.Clear(); } } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); theFuzzySystem.RulesDatabaseSet[0] = Systems_ready_to_test[best_index]; return(theFuzzySystem); }
public override SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf config) { start_add_rules = Approximate.RulesDatabaseSet.Count; SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { throw new System.FormatException("Что то не то с входными данными"); } OptimizeRullesShrinkConf Config = config as OptimizeRullesShrinkConf; count_Shrink_rule = Config.ORSCCountShrinkRules; int count_of_swith_off = count_Shrink_rule; List <byte> Varians_of_run_system = new List <byte>(); for (int i = 0; i < Approximate.RulesDatabaseSet[0].RulesDatabase.Count; i++) { Varians_of_run_system.Add(1); } for (int i = 0; i < count_of_swith_off; i++) { Varians_of_run_system[i] = 0; } Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { KnowlegeBaseSARules temp_rules = new KnowlegeBaseSARules(result.RulesDatabaseSet[0], Pull_of_systems[i]); temp_rules.TrimTerms(); result.RulesDatabaseSet.Add(temp_rules); result.UnlaidProtectionFix(result.RulesDatabaseSet[start_add_rules + i]); errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[start_add_rules + i])); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); KnowlegeBaseSARules best = result.RulesDatabaseSet[start_add_rules + best_index]; result.RulesDatabaseSet.Clear(); result.RulesDatabaseSet.Add(best); Console.WriteLine(Pull_of_systems.Count()); result.RulesDatabaseSet[0].TermsSet.Trim(); // result.UnlaidProtectionFix(); return(result); }
void fullInit() { populationMassive = new KnowlegeBaseSARules[currentConf.GENCPopulationSize]; childrenMassive = new KnowlegeBaseSARules[currentConf.GENCCountChild]; for (int i = 0; i < currentConf.GENCPopulationSize; i++) { populationMassive[i] = new KnowlegeBaseSARules(fullFuzzySystem.RulesDatabaseSet[0]); } //Parallel.For(1, (currentConf.Особей_в_популяции - 1), i => for (int i = 1; i < currentConf.GENCPopulationSize; i++) { double[] tempMassive = new double[populationMassive[i].all_conq_of_rules.Count()]; //Parallel.For(0, (populationMassive[i].all_conq_of_rules.Count() - 1), j => for (int j = 0; j < populationMassive[i].all_conq_of_rules.Count(); j++) { tempMassive[j] = initFunc(populationMassive[i].all_conq_of_rules[j], currentConf.GENCScateDeverceInit, fullFuzzySystem.LearnSamplesSet.OutputAttribute.Max, fullFuzzySystem.LearnSamplesSet.OutputAttribute.Min); } populationMassive[i].all_conq_of_rules = tempMassive; //}); for (int j = 0; j < populationMassive[i].TermsSet.Count; j++) //Parallel.For(0, populationMassive[i].TermsSet.Count, j => { tempMassive = populationMassive[i].TermsSet[j].Parametrs.Clone() as double[]; for (int u = 0; u < populationMassive[i].TermsSet[j].Parametrs.Count(); u++) //Parallel.For(0, populationMassive[i].TermsSet[j].Parametrs.Count(), u => { tempMassive[u] = initFunc(tempMassive[u], currentConf.GENCScateDeverceInit, fullFuzzySystem.LearnSamplesSet.InputAttributes[populationMassive[i].TermsSet[j].NumVar].Max, fullFuzzySystem.LearnSamplesSet.InputAttributes[populationMassive[i].TermsSet[j].NumVar].Min); // result.LearnSamplesSet.InputAttributeMax(fuzzyRulesDatabaseMassive[i].TermsSet[j].Max) // fuzzyRulesDatabaseMassive[i].TermsSet[j] .Parametrs[u] //}); } populationMassive[i].TermsSet[j].Parametrs = tempMassive; } //}); } //}); }
public override SAFuzzySystem Generate(SAFuzzySystem Approximate, IGeneratorConf config) { type_alg = ((kMeanRulesGeneratorConfig)config).KMRGTypeAlg; count_rules = ((kMeanRulesGeneratorConfig)config).KMRGCountRules; type_func = ((kMeanRulesGeneratorConfig)config).KMRGTypeFunc; nebulisation_factor = ((kMeanRulesGeneratorConfig)config).KMRGExponentialWeight; Max_iteration = ((kMeanRulesGeneratorConfig)config).KMRGIteraton; need_precision = ((kMeanRulesGeneratorConfig)config).KMRGAccuracy; Approxk_mean_base K_Agl = null; switch (type_alg) { case Type_k_mean_algorithm.GathGeva: K_Agl = new Approxk_mean_Gath_Geva(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break; case Type_k_mean_algorithm.GustafsonKessel: K_Agl = new Approxk_mean_Gustafson_kessel(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break; case Type_k_mean_algorithm.FCM: K_Agl = new Approxk_mean_base(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break; } K_Agl.Calc(); KnowlegeBaseSARules New_Rules = new KnowlegeBaseSARules(); for (int i = 0; i < count_rules; i++) { int [] order_terms = new int [Approximate.LearnSamplesSet.CountVars]; List <Term> term_set = new List <Term>(); for (int j = 0; j < Approximate.LearnSamplesSet.CountVars; j++) { Term temp_term = Term.MakeTerm(K_Agl.Centroid_cordinate_S[i][j], Math.Sqrt(Calc_distance_for_member_ship_function_for_Clust(i, j, K_Agl)) * 3, type_func, j); term_set.Add(temp_term); } New_Rules.constuct__and_add_the_Rule(term_set, Approximate); } SAFuzzySystem Result = Approximate; if (Result.RulesDatabaseSet.Count > 0) { Result.RulesDatabaseSet[0] = New_Rules; } else { Result.RulesDatabaseSet.Add(New_Rules); } Result.UnlaidProtectionFix(Result.RulesDatabaseSet[0]); GC.Collect(); Result.RulesDatabaseSet[0].TermsSet.Trim(); return(Result); }