public void MichalewiczNonUniformAllPositionsManipulatorApplyTest() { TestRandom random = new TestRandom(); RealVector parent, expected; DoubleValue generationsDependency; DoubleMatrix bounds; IntValue currentGeneration, maximumGenerations; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); expected = new RealVector(new double[] { 0.45, 0.22, 0.3, 0.6, 0.14 }); bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } }); generationsDependency = new DoubleValue(0.1); currentGeneration = new IntValue(1); maximumGenerations = new IntValue(4); MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent)); // The following test is not based on published examples exceptionFired = false; random.Reset(); random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } }); generationsDependency = new DoubleValue(0.1); currentGeneration = new IntValue(5); //current generation > max generation maximumGenerations = new IntValue(4); try { MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public override void updateStep6(RealVector nBazaWart, List<String> nBazaNazwa) { tab.updateWektorBazaNazwy(nBazaNazwa); tab.updateWektorBazaWart(nBazaWart); tab.usunInformacjeZZc(); tab.usunInformacjeZPrawejStr(); }
public void DiscreteCrossoverApplyTest() { TestRandom random = new TestRandom(); RealVector parent1, parent2, expected, actual; ItemArray<RealVector> parents; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 0, 0, 1, 0, 1 }; parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); parents = new ItemArray<RealVector>(new RealVector[] { parent1, parent2 }); expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.8 }); actual = DiscreteCrossover.Apply(random, parents); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 0, 0, 1, 0, 1, 0 }; parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); parents = new ItemArray<RealVector>(new RealVector[] { parent1, parent2 }); exceptionFired = false; try { actual = DiscreteCrossover.Apply(random, parents); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public void PolynomialAllPositionManipulatorApplyTest() { TestRandom random = new TestRandom(); RealVector parent, expected; DoubleValue contiguity, maxManipulation; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.2, 0.7, 0.8, 0.01, 0.1 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); expected = new RealVector(new double[] { 0.120213215256006, 0.249415354697564, 0.379786784743994, 0.322759240811056, -0.0182075293954083 }); contiguity = new DoubleValue(0.8); maxManipulation = new DoubleValue(0.2); PolynomialAllPositionManipulator.Apply(random, parent, contiguity, maxManipulation); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent)); // The following test is not based on published examples exceptionFired = false; random.Reset(); random.DoubleNumbers = new double[] { 0.2, 0.7, 0.8, 0.01, 0.1 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); contiguity = new DoubleValue(-1); //Contiguity value < 0 maxManipulation = new DoubleValue(0.2); try { PolynomialAllPositionManipulator.Apply(random, parent, contiguity, maxManipulation); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public void HeuristicCrossoverApplyTest() { TestRandom random = new TestRandom(); RealVector parent1, parent2, expected, actual; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.3 }; parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.14, 0.23, 0.3, 0.59, -0.11 }); actual = HeuristicCrossover.Apply(random, parent1, parent2); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.3 }; parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); exceptionFired = false; try { actual = HeuristicCrossover.Apply(random, parent1, parent2); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public void PolynomialOnePositionManipulatorApplyTest() { TestRandom random = new TestRandom(); RealVector parent, expected; DoubleValue contiguity, maxManipulation; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 3 }; random.DoubleNumbers = new double[] { 0.2 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.1261980542102, 0.1 }); contiguity = new DoubleValue(0.2); maxManipulation = new DoubleValue(0.7); PolynomialOnePositionManipulator.Apply(random, parent, contiguity, maxManipulation); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent)); // The following test is not based on published examples exceptionFired = false; random.Reset(); random.IntNumbers = new int[] { 3 }; random.DoubleNumbers = new double[] { 0.2 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); contiguity = new DoubleValue(-1); //Contiguity value < 0 maxManipulation = new DoubleValue(0.2); try { PolynomialOnePositionManipulator.Apply(random, parent, contiguity, maxManipulation); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public Wektor(Point _start, Type t,RealVector v) { elementyWektora = new List<PodstElem>(); start = _start; typ = t; setElementy(v); }
public void SinglePointCrossoverApplyTest() { TestRandom random = new TestRandom(); RealVector parent1, parent2, expected, actual; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 3 }; parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.2, 0.8 }); actual = SinglePointCrossover.Apply(random, parent1, parent2); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 2 }; parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); exceptionFired = false; try { actual = SinglePointCrossover.Apply(random, parent1, parent2); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 5 }; // should not have an effect parent1 = new RealVector(new double[] { 0.2, 0.4 }); parent2 = new RealVector(new double[] { 0.6, 0.1 }); expected = new RealVector(new double[] { 0.2, 0.1 }); actual = SinglePointCrossover.Apply(random, parent1, parent2); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples }
public RealVector getBazaWartosci() { RealVector temp = new RealVector(); for (int i = 0; i < bazaPocz.Count; i++) { temp.Add(0.0); } return temp; }
public void odswiez(RealVector v) { int i = 0; foreach (PodstElem e in elementyWektora) { e.setTekst(v[i].ToString("0.00")); i++; } }
public void BlendAlphaCrossoverApplyTest() { TestRandom random = new TestRandom(); RealVector parent1, parent2, expected, actual; DoubleValue alpha; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.5, 0.5, 0.5, 0.5, 0.5 }; alpha = new DoubleValue(0.5); parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.3, 0.15, 0.3, 0.35, 0.45 }); actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 }; alpha = new DoubleValue(0.25); parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 }); actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 }; alpha = new DoubleValue(-0.25); // negative values for alpha are not allowed parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 }); exceptionFired = false; try { actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25, .75 }; alpha = new DoubleValue(0.25); parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 }); exceptionFired = false; try { actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
/** Instantiates the SVM model as the average model of the input SVMs. */ SVM(List<SVM> svmList) { int dim = svmList[0].GetDimension(); var w = new RealVector(dim); foreach (SVM svm in svmList) { w.Add(svm.getWeights()); } this.weights = w.ScaleThis(1.0 / svmList.Count); }
public static RealVector getColumn(int column, RealMatrix m) { RealVector v = new RealVector(m.Count()); int i = 0; foreach (List<double> vecM in m) { v[i] = vecM[column]; i++; } return v; }
/** Instantiates SVM from weights given as a string. */ SVM(String input) { var parsedInput = input.Split(' ').Select(Double.Parse).ToList(); double[] w = new double[parsedInput.Count]; int cnt = 0; foreach (double coef in parsedInput) { w[cnt++] = coef; } this.weights = new RealVector(w); }
public static bool RealVectorIsAlmostEqualByPosition(RealVector p1, RealVector p2) { bool equal = (p1.Length == p2.Length); if (equal) { for (int i = 0; i < p1.Length; i++) { if (!p1[i].IsAlmost(p2[i])) { equal = false; break; } } } return equal; }
public static double[] get_vector(RealVector src) { IntPtr ptr = modshogunPINVOKE.RealVector_get_vector__SWIG_1(RealVector.getCPtr(src)); if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve(); int[] size = new int[1]; Marshal.Copy(ptr, size, 0, 1); int len = size[0]; double[] ret = new double[len]; Marshal.Copy(new IntPtr(ptr.ToInt64() + Marshal.SizeOf(typeof(int))), ret, 0, len); return ret; }
public override void inicjalizacja( RealVector wekC, List<String> wekCNazwy, List<String> bazaNaz, RealVector bazaWart, RealMatrix m, RealVector prawaStr) { tab = new tabela.Tabela(); tab.setWielkoscIInit(wekC.Count, bazaWart.Count); tab.updateWektorC(wekC); tab.updateWektorNazwC(wekCNazwy); tab.updateWektorBazaNazwy(bazaNaz); tab.updateWektorBazaWart(bazaWart); tab.updateMtx(m); tab.updatePrawaStronaWart(prawaStr); }
public void UniformOnePositionManipulatorApplyTest() { TestRandom random = new TestRandom(); RealVector parent, expected; DoubleMatrix bounds; // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 3 }; random.DoubleNumbers = new double[] { 0.2 }; parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.3, 0.1 }); bounds = new DoubleMatrix(new double[,] { { 0.2, 0.7 } }); UniformOnePositionManipulator.Apply(random, parent, bounds); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent)); }
public static int indexMinWartoscWektora(RealVector v) { if (v.Count == 0) return -1; int index = 0; double temp = v[0]; for (int i = 1; i < v.Count; i++) { if (v[i] < temp) { temp = v[i]; index = i; } } return index; }
bool typZadania; // 0 -max, 1-min #endregion Fields #region Constructors public Algorytm(RealVector wekC,List<String> wekCNazwy, List<String> bazaNaz,RealVector bazaWart, RealMatrix m,RealVector prawaStr,bool typ ) { WektorC = wekC; WektorNazwC = wekCNazwy; BazaNazwy = bazaNaz; BazaWartosci = bazaWart; mtx = m; prawaStrona = prawaStr; typZadania = typ; Z = new RealVector(WektorC.Count); Zc = new RealVector(WektorC.Count); obserw = new List<Obserwator>(); nrIteracji = 0; nrKroku = 0; }
public void SimulatedBinaryCrossoverApplyTest() { TestRandom random = new TestRandom(); RealVector parent1, parent2, expected, actual; DoubleValue contiguity; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.3, 0.9, 0.7, 0.2, 0.8, 0.1, 0.2, 0.3, 0.4, 0.8, 0.7 }; contiguity = new DoubleValue(0.3); parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); expected = new RealVector(new double[] { 0.644880972204315, 0.0488239539275703, 0.3, 0.5, 0.1 }); actual = SimulatedBinaryCrossover.Apply(random, parent1, parent2, contiguity); Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.3, 0.9, 0.7, 0.2, 0.8, 0.1, 0.2, 0.3, 0.4, 0.8, 0.7 }; contiguity = new DoubleValue(0.3); parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); exceptionFired = false; try { actual = SimulatedBinaryCrossover.Apply(random, parent1, parent2, contiguity); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); // The following test is not based on published examples random.Reset(); random.DoubleNumbers = new double[] { 0.3, 0.9, 0.7, 0.2, 0.8, 0.1, 0.2, 0.3, 0.4, 0.8, 0.7 }; contiguity = new DoubleValue(-0.3); // contiguity < 0 parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); exceptionFired = false; try { actual = SimulatedBinaryCrossover.Apply(random, parent1, parent2, contiguity); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public RealVector(RealVector orig) : this(modshogunPINVOKE.new_RealVector__SWIG_5(RealVector.getCPtr(orig)), true) { if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve(); }
/// <summary> /// Evaluates the test function for a specific <paramref name="point"/>. /// </summary> /// <remarks>Calls <see cref="Apply"/>.</remarks> /// <param name="point">N-dimensional point for which the test function should be evaluated.</param> /// <returns>The result value of the Schwefel function at the given point.</returns> public override double Evaluate(RealVector point) { return(Apply(point)); }
public virtual void updateStep6(RealVector nBazaWart, List<String> nBazaNazwa) { }
public virtual void updateStep7(RealVector pStrona, RealMatrix mtx) { }
public virtual void updateStep1(RealVector wektorZ) { }
public virtual void updateStep2(RealVector wektorZc) { }
public virtual void inicjalizacja(RealVector wekC, List<String> wekCNazwy, List<String> bazaNaz, RealVector bazaWart, RealMatrix m, RealVector prawaStr) { }
protected abstract double G(RealVector y);
private double[] Penalize(RealVector x, RealVector t, IEnumerable <double> fitness) { var penalty = x.Zip(t, (a, b) => (a - b) * (a - b)).Sum() * 1E-6; return(fitness.Select((v, i) => Problem.Maximization[i] ? v - penalty : v + penalty).ToArray()); }
public RealVector getPrawaStrona() { RealVector temp = new RealVector(); foreach(Funkcja e in ograniczenia) temp.Add(double.Parse(e.getPrawaStrona())); return temp; }
internal static HandleRef getCPtr(RealVector obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }
// public bool getTyp() { return getFunkcjaCelu().getTypFunkcji(); } public RealMatrix getMtx() { RealMatrix temp = new RealMatrix(); foreach(Funkcja e in ograniczenia){ RealVector t = new RealVector(); for (int i = 0; i <e.getWspZmiennych().Count; i++) { t.Add(double.Parse(e.getWspZmiennych()[i])); } temp.Add(t); } return temp; }
public double[] Evaluate(RealVector individual) { return(TestFunction.Evaluate(individual, Objectives)); }