Esempio n. 1
0
        private static void CreateDatabaseWithNativeIndexes(File databaseDirectory)
        {
            // Create one index for every provider that we have
            foreach (SchemaIndex schemaIndex in SchemaIndex.values())
            {
                GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(databaseDirectory).setConfig(default_schema_provider, schemaIndex.providerName()).newGraphDatabase();
                string key = "key-" + schemaIndex.name();
                try
                {
                    Label labelOne = Label.label("one");
                    using (Transaction tx = Db.beginTx())
                    {
                        Db.schema().indexFor(labelOne).on(key).create();
                        tx.Success();
                    }

                    using (Transaction tx = Db.beginTx())
                    {
                        RandomValues randomValues = RandomValues.create();
                        for (int i = 0; i < 10_000; i++)
                        {
                            Db.createNode(labelOne).setProperty(key, randomValues.NextValue().asObject());
                        }
                        tx.Success();
                    }
                }
                finally
                {
                    Db.shutdown();
                }
            }
        }
Esempio n. 2
0
        private static RandomValues GetPropertyValues(object target)
        {
            var propertyMap = new RandomValues();

            try
            {
                var properties = target.GetType().GetProperties();
                foreach (var prop in properties)
                {
                    try
                    {
                        var key   = prop.Name;
                        var value = prop.GetValue(target).ToString();
                        propertyMap.Add(key, value);
                    }
                    catch
                    {
                        // following best practices and swallowing all exceptions :oP
                    }
                }
            }
            catch
            {
                // ...and release! i'm no fisherman
            }

            return(propertyMap);
        }
Esempio n. 3
0
        public void EncodingDecodingTest()
        {
            var randomString = RandomValues.RandomString(20);

            Console.WriteLine($"RandomValueTest - RandomString : {randomString}");
            Assert.Equal(20, randomString.Length);
        }
        public void TestBuildAndMultipleElements()
        {
            const int count = 5;
            // Arrange
            var mocks = new List <Mock <ISpecification <T> > >();

            for (var i = 0; i < count; ++i)
            {
                var spec = new Mock <ISpecification <T> >();
                spec.Setup(s => s.IsSatisfiedBy(It.IsAny <T>())).Returns(true);
                mocks.Add(spec);
            }

            // Act
            var builder       = mocks.Aggregate(new SpecificationBuilderAnd <T>() as ISpecificationContainerBuilder <T>, (current, item) => current.Add(new SimpleSpecificationBuilder <T>(() => item.Object)));
            var specification = builder.Build();

            // Assert
            Assert.That(Value.Of(builder.Items).Count().Is().EqualTo(count), "No of Items");
            Assert.That(Value.Of(specification).Is().TypeOf(typeof(AndSpecification <T>)), "Correct spec type");
            Assert.That(Value.Of(specification.IsSatisfiedBy(RandomValues.Value <T>())).Is().True(), "IsSatisfied = true");
            var idx = 0;

            foreach (var mock in mocks)
            {
                mock.Verify(s => s.IsSatisfiedBy(It.IsAny <T>()), Times.Once(), string.Format("Mock {0} not called", idx++));
            }
        }
 internal override object NextNodeId(RandomValues random, long item)
 {
     lock (this)
     {
         return(item);
     }
 }
 private void ChangeRandomNode(GraphDatabaseService db, int nodeCount, RandomValues random)
 {
     try
     {
         using (Transaction tx = Db.beginTx())
         {
             long     nodeId = random.Next(nodeCount);
             Node     node   = Db.getNodeById(nodeId);
             object[] keys   = Iterables.asCollection(node.PropertyKeys).ToArray();
             string   key    = ( string )random.Among(keys);
             if (random.NextFloat() < 0.1)
             {                             // REMOVE
                 node.RemoveProperty(key);
             }
             else
             {                             // CHANGE
                 node.SetProperty(key, random.NextValue().asObject());
             }
             tx.Success();
         }
     }
     catch (NotFoundException)
     {               // It's OK, it happens if some other thread deleted that property in between us reading it and
         // removing or setting it
     }
 }
Esempio n. 7
0
        protected internal override void DoWork()
        {
            _txLogger.info("SuccessCount: " + _txSuccessCount + " FailCount: " + _txFailCount);
            RandomValues randomValues = RandomValues.create();

            try
            {
                _cluster.coreTx((db, tx) =>
                {
                    Node node = Db.createNode(_label);
                    for (int i = 1; i <= 8; i++)
                    {
                        node.setProperty(Prop(i), randomValues.NextValue().asObject());
                    }
                    tx.success();
                });
            }
            catch (Exception e)
            {
                _txFailCount++;

                if (IsInterrupted(e) || IsTransient(e))
                {
                    // whatever let's go on with the workload
                    return;
                }

                throw new Exception(e);
            }

            _txSuccessCount++;
        }
Esempio n. 8
0
        private void CreateLayers(int[] layers)
        {
            this.Layers = layers;
            List <Neuron> lastLayer = new List <Neuron>();

            for (int i = 0; i < layers.Length; i++)
            {
                List <Neuron> currentLayer = new List <Neuron>();
                if (i == 0)
                {
                    for (int i2 = 0; i2 < layers[i]; i2++)
                    {
                        inputNeurons.Add(new InputNeuron());
                    }
                    currentLayer.AddRange(inputNeurons);
                }
                else
                {
                    for (int i2 = 0; i2 < layers[i]; i2++)
                    {
                        CalculatedNeuron neuron = new CalculatedNeuron(activationFunction);
                        foreach (Neuron lastNeuron in lastLayer)
                        {
                            neuron.AddConnection(new NeuronConnection(lastNeuron, RandomValues.RandomDouble().Map(0, 1, -1, 1)));
                        }
                        currentLayer.Add(neuron);
                    }
                    calculatedNeurons.Add(currentLayer.Cast <CalculatedNeuron>().ToArray());
                }
                lastLayer = currentLayer;
            }
        }
Esempio n. 9
0
        public NeuralNetwork DoSexyTimeWith(NeuralNetwork other)
        {
            if (Array.Equals(other.Layers, Layers))
            {
                NeuralNetwork newNet = new NeuralNetwork(Layers, activationFunction);

                for (int layer = Layers.Length - 2; layer >= 0; layer--)
                {
                    for (int neuron = Layers[layer + 1] - 1; neuron >= 0; neuron--)
                    {
                        double[] factors      = calculatedNeurons[layer][neuron].GetFactors();
                        double[] otherFactors = other.calculatedNeurons[layer][neuron].GetFactors();
                        for (int i = 0; i < factors.Length; i++)
                        {
                            if (RandomValues.RandomDouble() > 0.5)
                            {
                                factors[i] = otherFactors[i];
                            }
                            else if (RandomValues.RandomDouble() <= 0.25)
                            {
                                factors[i] = (otherFactors[i] + factors[i]) / 2.0;
                            }
                        }
                        newNet.calculatedNeurons[layer][neuron].SetFactors(factors);
                    }
                }

                return(newNet);
            }
            else
            {
                throw new ArgumentException("Cannot breed between different networks");
            }
        }
Esempio n. 10
0
            internal override object NextNodeId(RandomValues random, long item)
            {
                sbyte[] randomBytes = random.NextByteArray(10, 10).asObjectCopy();
                string  result      = System.Guid.nameUUIDFromBytes(randomBytes).ToString();

                Strings[toIntExact(item)] = result;
                return(result);
            }
 internal virtual ValueType[] RandomSetOfSupportedAndSortableTypes()
 {
     ValueType[] types = TestSuite.supportedValueTypes();
     types = RemoveSpatialTypes(types);                                               // <- don't use spatial values
     types = RandomValues.excluding(types, ValueType.STRING, ValueType.STRING_ARRAY); // <- don't use strings outside of BMP
     types = Random.randomValues().selection(types, 2, types.Length, false);
     return(types);
 }
Esempio n. 12
0
 double[] RandomDoubles()
 {
     double[] inp = new double[evolver.InputCount];
     for (int i = 0; i < inp.Length; i++)
     {
         inp[i] = RandomValues.RandomDouble() > 0.5 ? 1 : 0;
     }
     return(inp);
 }
Esempio n. 13
0
 internal RandomValueGenerator(ValueCreatorUtil <KEY, VALUE> outerInstance, RandomValues randomValues, ValueType[] types, double fractionDuplicates)
 {
     this._outerInstance      = outerInstance;
     this.Types               = types;
     this.FractionDuplicates  = fractionDuplicates;
     this.RandomValues        = randomValues;
     this.UniqueCompareValues = new HashSet <Value>();
     this.UniqueValues        = new List <Value>();
 }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConsistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes()
        {
            GraphDatabaseService db = CreateDatabase();

//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            Label[] labels = IntStream.range(1, 7).mapToObj(i => Label.label("LABEL" + i)).toArray(Label[] ::new);
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            RelationshipType[] relTypes = IntStream.range(1, 5).mapToObj(i => RelationshipType.withName("REL" + i)).toArray(RelationshipType[] ::new);
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            string[]     propertyKeys = IntStream.range(1, 7).mapToObj(i => "PROP" + i).toArray(string[] ::new);
            RandomValues randomValues = RandomValues.create();

            using (Transaction tx = Db.beginTx())
            {
                ThreadLocalRandom rng  = ThreadLocalRandom.current();
                int          nodeCount = 1000;
                IList <Node> nodes     = new List <Node>(nodeCount);
                for (int i = 0; i < nodeCount; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    Label[] nodeLabels = rng.ints(rng.Next(labels.Length), 0, labels.Length).distinct().mapToObj(x => labels[x]).toArray(Label[] ::new);
                    Node    node       = Db.createNode(nodeLabels);
                    Stream.of(propertyKeys).forEach(p => node.setProperty(p, rng.nextBoolean() ? p : randomValues.NextValue().asObject()));
                    nodes.Add(node);
                    int localRelCount = Math.Min(nodes.Count, 5);
                    rng.ints(localRelCount, 0, localRelCount).distinct().mapToObj(x => node.CreateRelationshipTo(nodes[x], relTypes[rng.Next(relTypes.Length)])).forEach(r => Stream.of(propertyKeys).forEach(p => r.setProperty(p, rng.nextBoolean() ? p : randomValues.NextValue().asObject())));
                }
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                for (int i = 1; i < labels.Length; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    Db.execute(format(NODE_CREATE, "nodes" + i, array(java.util.labels.Take(i).Select(Label::name).ToArray(string[] ::new)), array(Arrays.copyOf(propertyKeys, i)))).close();
                }
                for (int i = 1; i < relTypes.Length; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    Db.execute(format(RELATIONSHIP_CREATE, "rels" + i, array(java.util.relTypes.Take(i).Select(RelationshipType::name).ToArray(string[] ::new)), array(Arrays.copyOf(propertyKeys, i)))).close();
                }
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
                tx.Success();
            }

            Db.shutdown();

            AssertIsConsistent(CheckConsistency());
        }
Esempio n. 15
0
        public void TestAction()
        {
            // Arrange
            var subject    = RandomValues.Value <T>();
            var mockAction = new Mock <IInvokeDelegate>();
            var rule       = Rule.Create <T>(mockAction.Object.Action);

            // Act
            rule.Process(subject);

            // Assert
            mockAction.Verify(a => a.Action(subject), Times.Once());
        }
        public void TestSpecification()
        {
            // Arrange
            var candidate         = RandomValues.Value <T>();
            var mockSpecification = new Mock <ISpecification <T> >();
            var specification     = mockSpecification.Object;

            // Act
            specification.IsSatisfiedBy(candidate);

            // Assert
            mockSpecification.Verify(s => s.IsSatisfiedBy(candidate), Times.Once());
        }
        public void TestSpecificationPredicate()
        {
            // Arrange
            var candidate     = RandomValues.Value <T>();
            var mockAction    = new Mock <IInvokeDelegate>();
            var specification = Specification.Create <T>(mockAction.Object.Predicate);

            // Act
            specification.IsSatisfiedBy(candidate);

            // Assert
            mockAction.Verify(a => a.Predicate(candidate), Times.Once());
        }
Esempio n. 18
0
 public string Encrypt(string plainPassword)
 {
     if (!string.IsNullOrEmpty(plainPassword))
     {
         return(RandomValues.RandomString(48) + Convert.ToBase64String(Encoding.UTF8.GetBytes(
                                                                           Convert.ToBase64String(Encoding.UTF8.GetBytes(plainPassword))
                                                                           )));
     }
     else
     {
         return(string.Empty);
     }
 }
Esempio n. 19
0
        public void Evolve()
        {
            List <NeuralNetwork> allNewNetworks = new List <NeuralNetwork>();

            List <NeuralNetwork> networkList = networks.Select(kvp => kvp.Value).ToList();

            networkList.Sort((t1, t2) => { return(-fitnesses[t1.GetGuid()].CompareTo(fitnesses[t2.GetGuid()])); });

            List <NeuralNetwork> best10 = networkList.Take((int)(networkList.Count * 0.1)).ToList();

            List <double> fitness = networkList.Select(n => fitnesses[n.GetGuid()]).ToList();

            allNewNetworks.AddRange(networkList.Take(5).Select(n => n));
            double[] mutationParams = mutationFunction(maxFitness);
            allNewNetworks.AddRange(best10.SelectMany(n => n.Mutate(mutationParams[0], mutationParams[1], 4)));

            while (allNewNetworks.Count < networkList.Count * 0.75)
            {
                NeuralNetwork n1 = networkList[RandomValues.RandomInt(0, networkList.Count - 1)];
                NeuralNetwork n2 = networkList[RandomValues.RandomInt(0, networkList.Count - 1)];
                if (n1.WantsSexyTimeWith(n2) && n2.WantsSexyTimeWith(n1))
                {
                    allNewNetworks.Add(n1.DoSexyTimeWith(n2));
                }
            }

            while (allNewNetworks.Count < networkList.Count)
            {
                int[] layers = new int[RandomValues.RandomInt(layerLength.Item1, layerLength.Item2)];
                for (int i = 0; i < layers.Length; i++)
                {
                    layers[i] = RandomValues.RandomInt(layerRange.Item1, layerRange.Item2);
                }
                layers[0] = inputs;
                layers[layers.Length - 1] = outputs;
                NeuralNetwork network = new NeuralNetwork(layers, activationFunction);
                allNewNetworks.Add(network);
            }

            networks.Clear();
            fitnesses.Clear();

            foreach (NeuralNetwork network in allNewNetworks)
            {
                networks.Add(network.GetGuid(), network);
            }

            generation++;
        }
Esempio n. 20
0
 public void RandomPropertyTest()
 {
     foreach (var awrr in RandomValues.ArrayOf(RandomValues.Int))
     {
         Equal(awrr, awrr);
     }
     foreach (var arr in new RandomValues.Sample <int[]>(RandomValues.ArrayOf(RandomValues.Int)))
     {
         Equal(arr, arr);
     }
     foreach (var arr in new RandomValues.Sample <int[]>())
     {
         Equal(arr, arr);
     }
 }
Esempio n. 21
0
        public virtual T Random(RandomValues random)
        {
            float value      = random.NextFloat();
            float comparison = 0.5f;

            foreach (T item in _items)
            {
                if (value >= comparison)
                {
                    return(item);
                }
                comparison /= 2f;
            }
            return(_items[_items.Length - 1]);
        }
        public void TestSpecificationNot([Values(false, true)] bool operand)
        {
            // Arrange
            var candidate          = RandomValues.Value <T>();
            var innerSpecification = Specification.Create <T>(__ => operand);
            var specification      = innerSpecification.Not();

            // Act
            var isSatisfied = specification.IsSatisfiedBy(candidate);

            // Assert
            var expected = !operand;

            Assert.That(Value.Of(isSatisfied).Is().EqualTo(expected), string.Format("Not {0}", operand));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideResultInOrderIfCapable() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideResultInOrderIfCapable()
        {
            int label = Token.nodeLabel("Node");
            int prop  = Token.propertyKey("prop");

            RandomValues   randomValues = RandomRule.randomValues();
            IndexReference index        = SchemaRead.index(label, prop);

            for (int i = 0; i < _nIterations; i++)
            {
                ValueType    type  = randomValues.Among(_targetedTypes);
                IndexOrder[] order = index.OrderCapability(type.valueGroup.category());
                foreach (IndexOrder indexOrder in order)
                {
                    if (indexOrder == IndexOrder.NONE)
                    {
                        continue;
                    }
                    NodeValueTuple from = new NodeValueTuple(this, long.MinValue, randomValues.NextValueOfType(type));
                    NodeValueTuple to   = new NodeValueTuple(this, long.MaxValue, randomValues.NextValueOfType(type));
                    if (COMPARATOR.compare(from, to) > 0)
                    {
                        NodeValueTuple tmp = from;
                        from = to;
                        to   = tmp;
                    }
                    bool fromInclusive = randomValues.NextBoolean();
                    bool toInclusive   = randomValues.NextBoolean();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> range = org.neo4j.internal.kernel.api.IndexQuery.range(prop, from.getOnlyValue(), fromInclusive, to.getOnlyValue(), toInclusive);
                    IndexQuery.RangePredicate <object> range = IndexQuery.range(prop, from.OnlyValue, fromInclusive, to.OnlyValue, toInclusive);

                    using (NodeValueIndexCursor node = Cursors.allocateNodeValueIndexCursor())
                    {
                        Read.nodeIndexSeek(index, node, indexOrder, false, range);

                        IList <long> expectedIdsInOrder = expectedIdsInOrder(from, fromInclusive, to, toInclusive, indexOrder);
                        IList <long> actualIdsInOrder   = new List <long>();
                        while (node.Next())
                        {
                            actualIdsInOrder.Add(node.NodeReference());
                        }

                        assertEquals(expectedIdsInOrder, actualIdsInOrder, "actual node ids not in same order as expected");
                    }
                }
            }
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            var    catList  = new List <Cat>();
            string catName  = "Unnamed";
            string catColor = "Unknown";

            Console.WriteLine("Hello World!");
            for (int i = 0; i < 10; i++)
            {
                catName = "Cat" + Sequence.NextValue();
                RandomValues ran = new RandomValues();
                catColor = ran.GetRandomColor();
                catList.Add(new Cat(catName, catColor));
                catList[i].SayMiau();
            }
        }
Esempio n. 25
0
        public void TestFollowOnAction()
        {
            // Arrange
            var subject     = RandomValues.Value <T>();
            var mockAction2 = new Mock <IInvokeDelegate>();
            var rule2       = Rule.Create <T>(mockAction2.Object.Action);
            var mockAction1 = new Mock <IInvokeDelegate>();
            var rule1       = Rule.Create <T>(mockAction1.Object.Action).FollowOn(rule2);

            // Act
            rule1.Process(subject);

            // Assert
            mockAction1.Verify(a => a.Action(subject), Times.Once());
            mockAction2.Verify(a => a.Action(subject), Times.Once());
        }
        public void TestSpecificationOr([Values(false, true)] bool lhs, [Values(false, true)] bool rhs)
        {
            // Arrange
            var candidate        = RandomValues.Value <T>();
            var lhsSpecification = Specification.Create <T>(__ => lhs);
            var rhsSpecification = Specification.Create <T>(__ => rhs);
            var specification    = lhsSpecification.Or(rhsSpecification);

            // Act
            var isSatisfied = specification.IsSatisfiedBy(candidate);

            // Assert
            var expected = lhs || rhs;

            Assert.That(Value.Of(isSatisfied).Is().EqualTo(expected), string.Format("{0} Or {1}", lhs, rhs));
        }
        public void TestSpecificationOr([Values(false, true)] bool p1, [Values(false, true)] bool p2, [Values(false, true)] bool p3)
        {
            // Arrange
            var candidate      = RandomValues.Value <T>();
            var specification1 = Specification.Create <T>(__ => p1);
            var specification2 = Specification.Create <T>(__ => p2);
            var specification3 = Specification.Create <T>(__ => p3);
            var specification  = specification1.Or(specification2).Or(specification3);

            // Act
            var isSatisfied = specification.IsSatisfiedBy(candidate);

            // Assert
            var expected = p1 || p2 || p3;

            Assert.That(Value.Of(isSatisfied).Is().EqualTo(expected), string.Format("{0} OR {1} OR {2}", p1, p2, p3));
        }
Esempio n. 28
0
            public override void Run()
            {
                RandomValues randomValues = RandomValues.create();

                awaitLatch(StartSignal);
                while (!EndSignal.get())
                {
                    using (Transaction transaction = DatabaseService.beginTx())
                    {
                        try
                        {
                            int operationType = randomValues.NextIntValue(3).value();
                            switch (operationType)
                            {
                            case 0:
                                long targetNodeId = randomValues.NextLongValue(TotalNodes).value();
                                DatabaseService.getNodeById(targetNodeId).delete();
                                break;

                            case 1:
                                long nodeId = randomValues.NextLongValue(TotalNodes).value();
                                Node node   = DatabaseService.getNodeById(nodeId);
                                IDictionary <string, object> allProperties = node.AllProperties;
                                foreach (string key in allProperties.Keys)
                                {
                                    node.SetProperty(key, randomValues.NextValue().asObject());
                                }
                                break;

                            case 2:
                                Node nodeToUpdate = DatabaseService.createNode(Label.label("label10"));
                                nodeToUpdate.SetProperty("property", randomValues.NextValue().asObject());
                                break;

                            default:
                                throw new System.NotSupportedException("Unknown type of index operation");
                            }
                            transaction.Success();
                        }
                        catch (Exception)
                        {
                            transaction.Failure();
                        }
                    }
                }
            }
Esempio n. 29
0
        private void PrePopulateDatabase(GraphDatabaseService database, Label testLabel, string propertyName)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.storable.RandomValues randomValues = org.neo4j.values.storable.RandomValues.create();
            RandomValues randomValues = RandomValues.create();

            for (int j = 0; j < 10_000; j++)
            {
                using (Transaction transaction = database.BeginTx())
                {
                    Node   node     = database.CreateNode(testLabel);
                    object property = randomValues.NextValue().asObject();
                    node.SetProperty(propertyName, property);
                    transaction.Success();
                }
            }
        }
Esempio n. 30
0
 public void Init()
 {
     for (int pop = 0; pop < netPopulations; pop++)
     {
         int[] layers = new int[RandomValues.RandomInt(layerLength.Item1, layerLength.Item2)];
         for (int i = 0; i < layers.Length; i++)
         {
             layers[i] = RandomValues.RandomInt(layerRange.Item1, layerRange.Item2);
         }
         layers[0] = inputs;
         layers[layers.Length - 1] = outputs;
         for (int net = 0; net < netsPerPopulation; net++)
         {
             NeuralNetwork network = new NeuralNetwork(layers, activationFunction);
             networks.Add(network.Guid, network);
         }
     }
 }
Esempio n. 31
0
        private static RandomValues GetPropertyValues(object target)
        {
            var propertyMap = new RandomValues();

            try
            {
                var properties = target.GetType().GetProperties();
                foreach (var prop in properties)
                {
                    try
                    {
                        var key = prop.Name;
                        var value = prop.GetValue(target).ToString();
                        propertyMap.Add(key, value);
                    }
                    catch
                    {
                        // following best practices and swallowing all exceptions :oP
                    }
                }
            }
            catch
            {
                // ...and release! i'm no fisherman
            }

            return propertyMap;
        }