Ejemplo n.º 1
0
        public Nwn2Fitters()
        {
            onlyCreatures         = new InstanceFitter(NWN2ObjectType.Creature, "a creature");
            onlyDoors             = new InstanceFitter(NWN2ObjectType.Door, "a door");
            onlyItems             = new InstanceFitter(NWN2ObjectType.Item, "an item");
            onlyPlaceables        = new InstanceFitter(NWN2ObjectType.Placeable, "a placeable");
            onlyStores            = new InstanceFitter(NWN2ObjectType.Store, "a store");
            onlyTriggers          = new InstanceFitter(NWN2ObjectType.Trigger, "a trigger");
            onlyWaypoints         = new InstanceFitter(NWN2ObjectType.Waypoint, "a waypoint");
            onlyDoorsOrPlaceables = new InstanceFitter(new List <NWN2ObjectType> {
                NWN2ObjectType.Door, NWN2ObjectType.Placeable
            }, "a door or placeable");
            onlyDestroyableObjects = new InstanceFitter(new List <NWN2ObjectType> {
                NWN2ObjectType.Creature,
                NWN2ObjectType.Door,
                NWN2ObjectType.Item,
                NWN2ObjectType.Light,
                NWN2ObjectType.Placeable,
                NWN2ObjectType.PlacedEffect,
                NWN2ObjectType.Trigger
            },
                                                        "something");

            onlyPlayers            = new PlayerFitter();
            onlyAreas              = new AreaFitter();
            onlyModules            = new ModuleFitter();
            onlyInstances          = new InstanceFitter();
            onlyInstancesOrPlayers = new InstancePlayerFitter();
            onlyCreaturesOrPlayers = new CreaturePlayerFitter();
            onlyEventRaisers       = new EventRaiserFitter();

            onlyNumbers = new NumberFitter();
            onlyStrings = new StringFitter();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new <see cref="Nwn2TriggerControl"/> instance.
        /// </summary>
        public Nwn2SlotTrigger(Fitter raiserFitter, string text1, string text2)
        {
            if (raiserFitter == null)
            {
                throw new ArgumentNullException("raiserFitter");
            }

            this.addressFactory = new Nwn2AddressFactory();

            raiserSlot = new BlockSlot("raiser", raiserFitter);
            raiserSlot.BorderThickness = new Thickness(1);
            raiserSlot.Padding         = new Thickness(4);
            raiserSlot.LayoutTransform = scaleTransform;

            InitializeComponent();

            this.text1.Text = text1;
            this.text2.Text = text2;

            raiserSlot.MoveableChanged += delegate
            {
                OnChanged(new EventArgs());
            };

            mainPanel.Children.Insert(1, raiserSlot);
        }
Ejemplo n.º 3
0
 public double Normalize(double time)
 {
     if (!initialized)
     {
         return(-1);
     }
     return(Fitter.GlucoseUnit(time));
 }
Ejemplo n.º 4
0
        static Fitter CreateFitter(Learner learner, Function network, Function loss, DeviceDescriptor device)
        {
            var trainer = Trainer.CreateTrainer(network, loss, loss, new List <Learner> {
                learner
            });
            var fitter = new Fitter(trainer, device);

            return(fitter);
        }
Ejemplo n.º 5
0
        public override void SetAlgorithm(TAlgorithm algorithm)
        {
            base.SetAlgorithm(algorithm);

            Initializer.SetAlgorithm(algorithm);
            Fitter.SetAlgorithm(algorithm);
            Selector.SetAlgorithm(algorithm);
            Crossover.SetAlgorithm(algorithm);
            Mutator.SetAlgorithm(algorithm);
        }
Ejemplo n.º 6
0
 public MainOperatorRCGA(Evaluator <TAlgorithm, TProblem, TSolution> evaluator,
                         CoordinatesInitializer <TAlgorithm, TProblem, TSolution> initializer,
                         Fitter <TAlgorithm, TProblem, TSolution> fitter,
                         Selector <TAlgorithm, TProblem, TSolution> selector,
                         CoordinatesCrossover <TAlgorithm, TProblem, TSolution> crossover,
                         CoordinatesMutator <TAlgorithm, TProblem, TSolution> mutator)
     : base(evaluator)
 {
     Initializer = initializer.DeepClone();
     Fitter      = fitter.DeepClone();
     Selector    = selector.DeepClone();
     Crossover   = crossover.DeepClone();
     Mutator     = mutator.DeepClone();
 }
Ejemplo n.º 7
0
        public override TSolution[] Apply(TSolution[] population)
        {
            Selector.BeforeSelection(population);
            var parents = Selector.Select(population);

            var children = new TSolution[parents.Length];

            for (int i = 0; i < children.Length; i++)
            {
                children[i] = new TSolution();
            }
            Crossover.CrossCoordinates(parents, children);

            Mutator.MutateCoordinates(children);
            Evaluator.Evaluate(children);
            Fitter.Fit(children);
            return(children);
        }
Ejemplo n.º 8
0
        public double Coefficient()
        {
            List <double> predits = new List <double>();

            foreach (double x in Retention)
            {
                predits.Add(Fitter.GlucoseUnit(x));
            }
            double mean       = Guis.Average();
            double ss_total   = 0;
            double ss_residue = 0;

            for (int i = 0; i < predits.Count; i++)
            {
                ss_total   += (Guis[i] - mean) * (Guis[i] - mean);
                ss_residue += (Guis[i] - predits[i]) * (Guis[i] - predits[i]);
            }
            return(1.0 - ss_residue / ss_total);
        }
Ejemplo n.º 9
0
 private void AddFitter(Fitter f)
 {
     fitters.Add(f.Name, f);
     window.tofFitFunctionCombo.Items.Add(f);
 }
Ejemplo n.º 10
0
 public void SpectrumFitFunctionChanged(object item)
 {
     spectrumFitter = (Fitter)item;
     window.ClearSpectrumFit();
 }
Ejemplo n.º 11
0
 public void TOFFitFunctionChanged(object item)
 {
     tofFitter = (Fitter)item;
     window.ClearTOFFit();
 }
Ejemplo n.º 12
0
        //[TestMethod]
        public void Fitter_Loop()
        {
            var inputShape      = new int[] { 28, 28, 1 };
            var numberOfClasses = 10;
            var outputShape     = new int[] { numberOfClasses };

            (var observations, var targets) = CreateArtificialData(inputShape, outputShape, observationCount: 10000);

            var dataType = DataType.Float;
            var device   = DeviceDescriptor.UseDefaultDevice();

            var random = new Random(232);
            Func <CNTKDictionary> weightInit = () => Initializers.GlorotNormal(random.Next());
            var biasInit = Initializers.Zero();

            // Create the architecture.
            var network = Layers.Input(inputShape, dataType)
                          .Dense(512, weightInit(), biasInit, device, dataType)
                          .ReLU()
                          .Dense(numberOfClasses, weightInit(), biasInit, device, dataType)
                          .Softmax();

            // setup input and target variables.
            var inputVariable  = network.Arguments[0];
            var targetVariable = Variable.InputVariable(network.Output.Shape, dataType);

            // loss
            var loss   = Losses.CategoricalCrossEntropy(network.Output, targetVariable);
            var metric = Metrics.Accuracy(network.Output, targetVariable);

            // setup trainer.
            var learner = Learners.MomentumSGD(network.Parameters());
            var trainer = CNTKLib.CreateTrainer(network, loss, metric, new LearnerVector {
                learner
            });

            // data names
            var observationsName = "observations";
            var targetsName      = "targets";

            // setup name to variable map.
            var nameToVariable = new Dictionary <string, Variable>
            {
                { observationsName, inputVariable },
                { targetsName, targetVariable },
            };

            // setup name to data map.
            var nameToData = new Dictionary <string, MemoryMinibatchData>
            {
                { observationsName, observations },
                { targetsName, targets }
            };

            var minibatchSource = new MemoryMinibatchSource(nameToVariable, nameToData, seed: 232, randomize: true);

            // setup Fitter
            var fitter = new Fitter(trainer, device);

            // variables for training loop.
            var inputMap = new Dictionary <Variable, Value>();

            var epochs    = 10;
            int batchSize = 32;

            for (int epoch = 0; epoch < epochs;)
            {
                var(minibatch, isSweepEnd) = minibatchSource.GetNextMinibatch(batchSize, device);
                fitter.FitNextStep(minibatch, batchSize);

                if (isSweepEnd)
                {
                    var currentLoss   = fitter.CurrentLoss;
                    var currentMetric = fitter.CurrentMetric;
                    fitter.ResetLossAndMetricAccumulators();

                    var traceOutput = $"Epoch: {epoch + 1:000} Loss = {currentLoss:F8}, Metric = {currentMetric:F8}";

                    ++epoch;

                    Trace.WriteLine(traceOutput);
                }
            }
        }
Ejemplo n.º 13
0
 public override void Initialize(TSolution[] population)
 {
     Initializer.InitializeCoordinates(population);
     Evaluator.Evaluate(population);
     Fitter.Fit(population);
 }
Ejemplo n.º 14
0
 public DoorOrPlaceableIsUnlocked(Fitter raiserFitter) : base(raiserFitter, "When", "is unlocked")
 {
 }
Ejemplo n.º 15
0
 public TriggerEntered(Fitter raiserFitter) : base(raiserFitter, "When walking into", String.Empty)
 {
 }
Ejemplo n.º 16
0
 public AreaEntered(Fitter raiserFitter) : base(raiserFitter, "When", "starts")
 {
 }
Ejemplo n.º 17
0
 public PlaceableUsed(Fitter raiserFitter) : base(raiserFitter, "When", "is used")
 {
 }
Ejemplo n.º 18
0
    public static Genome CrossOver(Genome parent1, Genome parent2, Fitter f)
    {
        Genome child = new Genome();

        var rand = new Random();

        // Add Disjoint and Excess Connections from Fitter Parent
        if (f == Fitter.Parent1)
        {
            // Add all nodes from the fitter parent
            foreach (Node n in parent1.Nodes.Values)
            {
                child.AddNodeCopy(n);
            }
            foreach (Connection c in parent1.Connections.Values)
            {
                if (!parent2.Connections.ContainsKey(c.Innovation))
                {
                    child.AddConnectionCopy(c);
                }
            }
        }
        else
        {
            foreach (Node n in parent2.Nodes.Values)
            {
                child.AddNodeCopy(n);
            }
            foreach (Connection c in parent2.Connections.Values)
            {
                if (!parent1.Connections.ContainsKey(c.Innovation))
                {
                    child.AddConnectionCopy(c);
                }
            }
        }

        // Go through again to add all the matching gene randomly
        foreach (Connection c1 in parent1.Connections.Values)
        {
            foreach (Connection c2 in parent2.connections.Values)
            {
                // If matching gene --> pick randomly (50/50)
                if (c1.Innovation == c2.Innovation)
                {
                    if (rand.Next(0, 2) == 0)
                    {
                        child.AddConnectionCopy(c1);
                    }
                    else
                    {
                        child.AddConnectionCopy(c2);
                    }
                    // Randomly enable disabled inherited connection
                    if (!c1.Expressed && !c2.Expressed)
                    {
                        double r = rand.NextDouble();
                        if (r < NEATController.ENABLE_CHANCE)
                        {
                            c2.Expressed = true;
                        }
                    }
                }
            }
        }

        return(child);
    }
Ejemplo n.º 19
0
        public void Run(string path, Counter counter)
        {
            ISpectrumReader reader = new ThermoRawSpectrumReader();

            reader.Init(path);

            IGUIFinder finder  = new BinarySearchFinder(PPM);
            IProcess   picking = new LocalNeighborPicking();
            Dictionary <int, List <GUI> > pointMaps = new Dictionary <int, List <GUI> >();

            int start = reader.GetFirstScan();
            int end   = reader.GetLastScan();

            Parallel.For(start, end, (i) =>
            {
                if (reader.GetMSnOrder(i) < 2)
                {
                    ISpectrum spectrum = picking.Process(reader.GetSpectrum(i));
                    lock (resultLock)
                    {
                        pointMaps[i] = finder.FindGlucoseUnits(spectrum);
                    }
                }
                counter.Add(end - start);
            });
            List <List <GUI> > points =
                pointMaps.OrderBy(p => p.Key).Select(p => p.Value).ToList();

            IGUISequencer sequencer = new DynamicProgrammingSequencer();
            List <GUI>    guiPoints = sequencer.Choose(points);

            Dictionary <int, GUI> guiSelected = new Dictionary <int, GUI>();

            foreach (GUI gui in guiPoints)
            {
                if (guiSelected.ContainsKey(gui.Unit))
                {
                    if (guiSelected[gui.Unit].Peak.GetIntensity() < gui.Peak.GetIntensity())
                    {
                        guiSelected[gui.Unit] = gui;
                    }
                }
                else
                {
                    guiSelected[gui.Unit] = gui;
                }
            }

            Retention.Clear();
            Guis.Clear();

            List <GUI> looped = guiSelected.Values.OrderBy(g => g.Scan).ToList();
            string     output = Path.Combine(Path.GetDirectoryName(path),
                                             Path.GetFileNameWithoutExtension(path) + ".csv");

            using (FileStream ostrm = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (StreamWriter writer = new StreamWriter(ostrm))
                {
                    writer.WriteLine("scan,time,gui,peak,intensity");
                    foreach (GUI gui in looped)
                    {
                        int    scan = gui.Scan;
                        double time = reader.GetRetentionTime(scan);
                        Retention.Add(time);
                        Guis.Add(gui.Unit);
                        writer.WriteLine(scan.ToString() + "," +
                                         time.ToString() + "," +
                                         gui.Unit.ToString() + "," +
                                         gui.Peak.GetMZ().ToString() + "," +
                                         gui.Peak.GetIntensity().ToString());
                    }
                    writer.Flush();
                }
            }
            Fitter.Fit(Retention, Guis);
        }
Ejemplo n.º 20
0
 public double Normalize(double time)
 {
     return(Fitter.GlucoseUnit(time));
 }
Ejemplo n.º 21
0
 public TriggerExited(Fitter raiserFitter) : base(raiserFitter, "When walking out of", String.Empty)
 {
 }
Ejemplo n.º 22
0
 public CreatureDies(Fitter raiserFitter) : base(raiserFitter, "When", "is killed")
 {
 }