Package org.uncommons.maths.binary

Examples of org.uncommons.maths.binary.BitString


    @Test
    public void testSeededPopulation()
    {
        CandidateFactory<BitString> factory = new BitStringFactory(candidateLength);
        BitString seed1 = new BitString("1111100000");
        BitString seed2 = new BitString("1010101010");
        List<BitString> seeds = new ArrayList<BitString>(2);
        seeds.add(seed1);
        seeds.add(seed2);
        List<BitString> population = factory.generateInitialPopulation(populationSize,
                                                                       seeds,
View Full Code Here


     */
    @Test(expectedExceptions = IllegalArgumentException.class)
    public void testTooManySeedCandidates()
    {
        CandidateFactory<BitString> factory = new BitStringFactory(candidateLength);
        BitString candidate = new BitString(candidateLength);
        // The following call should cause an exception since the 3 seed candidates
        // won't fit into a population of size 2.
        factory.generateInitialPopulation(2,
                                          Arrays.asList(candidate, candidate, candidate),
                                          FrameworkTestUtils.getRNG());
View Full Code Here

     */
    @Test
    public void testRandomMutation()
    {
        EvolutionaryOperator<BitString> mutation = new BitStringMutation(Probability.EVENS);
        BitString original = new BitString("111100101");
        List<BitString> population = Arrays.asList(original);
        for (int i = 0; i < 20; i++) // Perform several iterations to get different mutations.
        {
            population = mutation.apply(population, FrameworkTestUtils.getRNG());
            BitString mutated = population.get(0);
            assert mutated.getLength() == 9 : "Mutated bit string changed length.";
        }
    }
View Full Code Here

     * make the outcome predictable (all bits will be flipped).
     */
    @Test
    public void testSingleBitMutation()
    {
        BitString original = new BitString("111100101");
        EvolutionaryOperator<BitString> mutation = new BitStringMutation(Probability.ONE);                                                                        
        List<BitString> population = Arrays.asList(original);
        population = mutation.apply(population, FrameworkTestUtils.getRNG());
        BitString mutated = population.get(0);
        assert !mutated.equals(original) : "Mutation should be different from original.";
        assert mutated.getLength() == 9 : "Mutated bit string changed length.";
        int set = mutated.countSetBits();
        int unset = mutated.countUnsetBits();
        assert set == 5 || set == 7 : "Mutated bit string has wrong number of 1s: " + set;
        assert unset == 2 || unset == 4 : "Mutated bit string has wrong number of 0s: " + unset;
    }
View Full Code Here

   
    // the label is not included in the conditions
    this.nbConditions = DataSet.getDataSet().getNbAttributes() - 1;
   
    weights = new double[nbConditions];
    operators = new BitString(nbConditions);
    values = new double[nbConditions];
  }
View Full Code Here

TOP

Related Classes of org.uncommons.maths.binary.BitString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.