public FastVector GetDataSetAtts()
        {
            if (_fvWekaAttributes != null)
            {
                return(_fvWekaAttributes);
            }

            // Declare features
            FastVector fvWekaAttributes = new FastVector(DomPool.SelectorFeatures.Count() + 1);

            foreach (Feature currFeature in DomPool.SelectorFeatures)
            {
                weka.core.Attribute feature = new weka.core.Attribute(currFeature.ToString());
                fvWekaAttributes.addElement(feature);
            }

            // Declare the class attribute along with its values
            FastVector fvClassVal = new FastVector(2);

            fvClassVal.addElement("yes");
            fvClassVal.addElement("no");
            weka.core.Attribute ClassAttribute = new weka.core.Attribute("theClass", fvClassVal);

            // Declare the feature vector
            fvWekaAttributes.addElement(ClassAttribute);
            _fvWekaAttributes = fvWekaAttributes;

            return(_fvWekaAttributes);
        }
예제 #2
0
        public Identifier(Boolean isAnnotated, WhyTrainer wt)
        {
            this.isAnnotated = isAnnotated;
            this.wt          = wt;

            listWhoCandidates          = new List <Candidate>();
            listWhenCandidates         = new List <Candidate>();
            listWhereCandidates        = new List <Candidate>();
            listWhatCandidates         = new List <List <Token> >();
            listWhyCandidates          = new List <List <Token> >();
            listSecondaryWhyCandidates = new List <Candidate>();

            fvPOS = new FastVector(Token.PartOfSpeechTags.Length);
            foreach (String POS in Token.PartOfSpeechTags)
            {
                fvPOS.addElement(POS);
            }

            whoClassifier   = (Classifier)SerializationHelper.read(@"..\..\IdentifierModels\who.model");
            whenClassifier  = (Classifier)SerializationHelper.read(@"..\..\IdentifierModels\when.model");
            whereClassifier = (Classifier)SerializationHelper.read(@"..\..\IdentifierModels\where.model");
            whyClassifier   = (Classifier)SerializationHelper.read(@"..\..\IdentifierModels\why.model");

            initializeAnnotations();
        }
        public HashSet <HtmlNode> RunOnTestSeenSet()
        {
            HashSet <HtmlNode> classifierSelectedNodes = new HashSet <HtmlNode>();

            InitTestSeen();
            foreach (string featureString in FeaturesUsed)
            {
                HashSet <HtmlNode> resNodes = DomPool.TESTSeenRunXpathQuery(useNormalPerformanceQUERY(featureString));
                foreach (HtmlNode nd in resNodes)
                {
                    if (!testSeenAllNodes.Contains(nd))
                    {
                        continue;
                    }
                    testSeenNodeFeatures[nd].Add(featureString);
                }
            }

            FastVector fvWekaAttributes = GetDataSetAtts();
            Instances  testSet          = new Instances("TestSeenSet", fvWekaAttributes, 10);

            testSet.setClassIndex(fvWekaAttributes.size() - 1);

            foreach (HtmlNode currNode in testSeenAllNodes)
            {
                Instance item = new SparseInstance(fvWekaAttributes.size());

                for (int i = 0; i < fvWekaAttributes.size() - 1; i++)
                {
                    weka.core.Attribute currFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(i);
                    if (testSeenNodeFeatures[currNode].Contains(currFeature.name()))
                    {
                        item.setValue(currFeature, 1);
                    }
                    else
                    {
                        item.setValue(currFeature, 0);
                    }
                }

                //set the class
                weka.core.Attribute classFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(fvWekaAttributes.size() - 1);
                //string rightVal = DomPool.TargetNodes.Contains(currNode) ? "yes" : "no";
                item.setDataset(testSet);



                double classifierdv  = classifierTree.classifyInstance(item);
                string classifierVal = classFeature.value((int)classifierdv);

                if (classifierVal.Equals("yes"))
                {
                    classifierSelectedNodes.Add(currNode);
                }

                testSet.add(item);
            }

            return(classifierSelectedNodes);
        }
예제 #4
0
        private FastVector createWhereFastVector()
        {
            FastVector fvWhere = new FastVector(5 + whereWordsBefore * 2 + whereWordsAfter * 2);

            fvWhere.addElement(new weka.core.Attribute("word", (FastVector)null));
            fvWhere.addElement(new weka.core.Attribute("wordCount"));
            fvWhere.addElement(new weka.core.Attribute("sentence"));
            //fvWhere.addElement(new weka.core.Attribute("position"));
            //fvWhere.addElement(new weka.core.Attribute("sentenceStartProximity"));
            fvWhere.addElement(new weka.core.Attribute("wordScore"));
            for (int i = whereWordsBefore; i > 0; i--)
            {
                fvWhere.addElement(new weka.core.Attribute("word-" + i, (FastVector)null));
            }
            for (int i = 1; i <= whereWordsAfter; i++)
            {
                fvWhere.addElement(new weka.core.Attribute("word+" + i, (FastVector)null));
            }
            for (int i = whereWordsBefore; i > 0; i--)
            {
                fvWhere.addElement(new weka.core.Attribute("postag-" + i, fvPOS));
            }
            for (int i = 1; i <= whereWordsAfter; i++)
            {
                fvWhere.addElement(new weka.core.Attribute("postag+" + i, fvPOS));
            }
            FastVector fvClass = new FastVector(2);

            fvClass.addElement("yes");
            fvClass.addElement("no");
            fvWhere.addElement(new weka.core.Attribute("where", fvClass));
            return(fvWhere);
        }
예제 #5
0
        private static Instances CreateInstanceOnFly(double[] a, double[] b)
        {
            FastVector atts;
            Instances  data;

            double[] vals;

            // 1. set up attributes
            atts = new FastVector();
            // - numeric
            atts.addElement(new Attribute("att1"));
            atts.addElement(new Attribute("att2"));

            // 2. create Instances object
            data = new Instances("MyRelation", atts, 0);

            for (int i = 0; i < a.Length; ++i)
            {
                // 3. fill with data
                // first instance
                vals = new double[data.numAttributes()];
                // - numeric
                vals[0] = a[i];
                // - nominal
                vals[1] = b[i];
                data.add(new weka.core.DenseInstance(1.0, vals));
            }

            return(data);
        }
예제 #6
0
        private FastVector createWhyFastVector()
        {
            FastVector fvWhy = new FastVector(8 + whyWordsBefore * 2 + whyWordsAfter * 2);

            fvWhy.addElement(new weka.core.Attribute("candidate", (FastVector)null));
            fvWhy.addElement(new weka.core.Attribute("wordCount"));
            fvWhy.addElement(new weka.core.Attribute("sentence"));
            fvWhy.addElement(new weka.core.Attribute("candidateScore"));
            fvWhy.addElement(new weka.core.Attribute("numWho"));
            fvWhy.addElement(new weka.core.Attribute("numWhen"));
            fvWhy.addElement(new weka.core.Attribute("numWhere"));
            for (int i = whereWordsBefore; i > 0; i--)
            {
                fvWhy.addElement(new weka.core.Attribute("word-" + i, (FastVector)null));
            }
            for (int i = 1; i <= whereWordsAfter; i++)
            {
                fvWhy.addElement(new weka.core.Attribute("word+" + i, (FastVector)null));
            }
            for (int i = whyWordsBefore; i > 0; i--)
            {
                fvWhy.addElement(new weka.core.Attribute("postag-" + i, fvPOS));
            }
            for (int i = 1; i <= whyWordsAfter; i++)
            {
                fvWhy.addElement(new weka.core.Attribute("postag+" + i, fvPOS));
            }
            FastVector fvClass = new FastVector(2);

            fvClass.addElement("yes");
            fvClass.addElement("no");
            fvWhy.addElement(new weka.core.Attribute("why", fvClass));
            return(fvWhy);
        }
예제 #7
0
        private Instance createSingleWhoInstance(FastVector fvWho, Token candidate)
        {
            //first word-n attribute number
            int wordsBeforeFirstAttributeNumber = 6;
            //first pos-n attribute number
            int posBeforeFirstAttributeNumber = wordsBeforeFirstAttributeNumber + whoWordsBefore + whoWordsAfter;
            //word+1 attribute number
            int wordsAfterFirstAttributeNumber = wordsBeforeFirstAttributeNumber + whoWordsBefore;
            //pos+1 attribute number
            int posAfterFirstAttributeNumber = posBeforeFirstAttributeNumber + whoWordsBefore;

            int totalAttributeCount = wordsBeforeFirstAttributeNumber + whoWordsBefore * 2 + whoWordsAfter * 2 + 1;

            Instance whoCandidate = new DenseInstance(totalAttributeCount);

            whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(0), candidate.Value);
            whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(1), candidate.Value.Split(' ').Count());
            whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(2), candidate.Sentence);
            whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(3), candidate.Position);
            double sentenceStartProximity = -1;

            foreach (List <Token> tokenList in segregatedArticleCurrent)
            {
                if (tokenList.Count > 0 && tokenList[0].Sentence == candidate.Sentence)
                {
                    sentenceStartProximity = (double)(candidate.Position - tokenList[0].Position) / (double)tokenList.Count;
                    break;
                }
            }
            if (sentenceStartProximity > -1)
            {
                whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(4), sentenceStartProximity);
            }
            whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(5), candidate.Frequency);

            for (int i = whoWordsBefore; i > 0; i--)
            {
                if (candidate.Position - i - 1 >= 0)
                {
                    whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(whoWordsBefore - i + wordsBeforeFirstAttributeNumber), articleCurrent[candidate.Position - i - 1].Value);
                    if (articleCurrent[candidate.Position - i - 1].PartOfSpeech != null)
                    {
                        whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(whoWordsBefore - i + posBeforeFirstAttributeNumber), articleCurrent[candidate.Position - i - 1].PartOfSpeech);
                    }
                }
            }
            for (int i = 0; i < whoWordsAfter; i++)
            {
                if (candidate.Position + i < articleCurrent.Count)
                {
                    whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(wordsAfterFirstAttributeNumber + i), articleCurrent[candidate.Position + i].Value);
                    if (articleCurrent[candidate.Position + i].PartOfSpeech != null)
                    {
                        whoCandidate.setValue((weka.core.Attribute)fvWho.elementAt(posAfterFirstAttributeNumber + i), articleCurrent[candidate.Position + i].PartOfSpeech);
                    }
                }
            }
            return(whoCandidate);
        }
예제 #8
0
        private static FastVector PrepareFastVector()
        {
            var fastVector = new FastVector(_attributes.Count);

            foreach (var attribute in _attributes)
            {
                fastVector.addElement(attribute);
            }
            return(fastVector);
        }
예제 #9
0
파일: Diabetes.cs 프로젝트: gitzfibbon/ml
        private static Instances DefineBucketAttributes(int numBuckets)
        {
            FastVector attributes = new FastVector();

            FastVector numberOfTimesPregnant      = new FastVector();
            FastVector plasmaGlucoseConcentration = new FastVector();
            FastVector diastolicBloodPressure     = new FastVector();
            FastVector tricepsSkinFoldThickness   = new FastVector();
            FastVector twoHourSerumInsulin        = new FastVector();
            FastVector bmi = new FastVector();
            FastVector diabetesPedigreeFunction = new FastVector();
            FastVector age = new FastVector();

            for (int i = 0; i < numBuckets; i++)
            {
                string attributeValueName = i.ToString();

                numberOfTimesPregnant.addElement(attributeValueName);
                plasmaGlucoseConcentration.addElement(attributeValueName);
                diastolicBloodPressure.addElement(attributeValueName);
                tricepsSkinFoldThickness.addElement(attributeValueName);
                twoHourSerumInsulin.addElement(attributeValueName);
                bmi.addElement(attributeValueName);
                diabetesPedigreeFunction.addElement(attributeValueName);
                age.addElement(attributeValueName);
            }

            attributes.addElement(new weka.core.Attribute("numberOfTimesPregnant", numberOfTimesPregnant));
            attributes.addElement(new weka.core.Attribute("plasmaGlucoseConcentration", plasmaGlucoseConcentration));
            attributes.addElement(new weka.core.Attribute("diastolicBloodPressure", diastolicBloodPressure));
            attributes.addElement(new weka.core.Attribute("tricepsSkinFoldThickness", tricepsSkinFoldThickness));
            attributes.addElement(new weka.core.Attribute("twoHourSerumInsulin", twoHourSerumInsulin));
            attributes.addElement(new weka.core.Attribute("bmi", bmi));
            attributes.addElement(new weka.core.Attribute("diabetesPedigreeFunction", diabetesPedigreeFunction));
            attributes.addElement(new weka.core.Attribute("age", age));

            FastVector diabetes = new FastVector();

            diabetes.addElement("0"); // negative
            diabetes.addElement("1"); // positive
            attributes.addElement(new weka.core.Attribute("diagnosis", diabetes));

            Instances instances = new Instances("diabetes", attributes, 0);

            return(instances);
        }
예제 #10
0
        private Instance createSingleWhyInstance(FastVector fvWhy, Token candidate)
        {
            //first word-n attribute number
            int wordsBeforeFirstAttributeNumber = 7;
            //first pos-n attribute number
            int posBeforeFirstAttributeNumber = wordsBeforeFirstAttributeNumber + whyWordsBefore + whyWordsAfter;
            //word+1 attribute number
            int wordsAfterFirstAttributeNumber = wordsBeforeFirstAttributeNumber + whyWordsBefore;
            //pos+1 attribute number
            int posAfterFirstAttributeNumber = posBeforeFirstAttributeNumber + whyWordsBefore;

            int totalAttributeCount = wordsBeforeFirstAttributeNumber + whyWordsBefore * 2 + whyWordsAfter * 2 + 1;

            Instance whyCandidate = new DenseInstance(totalAttributeCount);

            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(0), candidate.Value);
            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(1), candidate.Value.Split(' ').Count());
            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(2), candidate.Sentence);
            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(3), candidate.Score);
            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(4), candidate.NumWho);
            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(5), candidate.NumWhen);
            whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(6), candidate.NumWhere);
            for (int i = whyWordsBefore; i > 0; i--)
            {
                if (candidate.Position - i - 1 >= 0)
                {
                    whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(whyWordsBefore - i + wordsBeforeFirstAttributeNumber), articleCurrent[candidate.Position - i - 1].Value);
                    if (articleCurrent[candidate.Position - i - 1].PartOfSpeech != null)
                    {
                        whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(whyWordsBefore - i + posBeforeFirstAttributeNumber), articleCurrent[candidate.Position - i - 1].PartOfSpeech);
                    }
                }
            }
            for (int i = 0; i < whyWordsAfter; i++)
            {
                if (candidate.Position + i < articleCurrent.Count)
                {
                    whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(wordsAfterFirstAttributeNumber + i), articleCurrent[candidate.Position + i].Value);
                    if (articleCurrent[candidate.Position + i].PartOfSpeech != null)
                    {
                        whyCandidate.setValue((weka.core.Attribute)fvWhy.elementAt(posAfterFirstAttributeNumber + i), articleCurrent[candidate.Position + i].PartOfSpeech);
                    }
                }
            }
            return(whyCandidate);
        }
예제 #11
0
        public static List <ClusteredDataObject> Clustering(RoughSetInformations roughSetInformations, List <DataObject> dataObjects)
        {
            _dataObjects = dataObjects;
            _attributes  = roughSetInformations.ArgumentNames.Select(argumentName => new Attribute(argumentName)).ToList();
            _fastVector  = PrepareFastVector();

            if (_dataObjects == null)
            {
                return(null);
            }

            _argumentsClustersRangeList = PrepareArgumentsClustersRangeList();

            SortArgumentsClustersRangeListItems();

            return(PrepareClusteredDataObjectsCollection());
        }
        int distanceComparer(Light a, Light b)
        {
            Vector3 posA  = a.transform.position;
            Vector3 posB  = b.transform.position;
            float   distA = FastVector.SqrDistance(ref camPos, ref posA);
            float   distB = FastVector.SqrDistance(ref camPos, ref posB);

            if (distA < distB)
            {
                return(-1);
            }
            if (distA > distB)
            {
                return(1);
            }
            return(0);
        }
예제 #13
0
        private Instances createWhyInstances()
        {
            FastVector fvWhy        = createWhyFastVector();
            Instances  whyInstances = new Instances("WhyInstances", fvWhy, listSecondaryWhyCandidates.Count);

            foreach (Token candidate in listSecondaryWhyCandidates)
            {
                if (candidate.Value == null)
                {
                    continue;
                }
                Instance whyInstance = createSingleWhyInstance(fvWhy, candidate);
                whyInstance.setDataset(whyInstances);
                whyInstances.add(whyInstance);
            }
            whyInstances.setClassIndex(fvWhy.size() - 1);
            return(whyInstances);
        }
예제 #14
0
        /// <summary>
        /// Creates and returns empty weka data set </summary>
        /// <param name="numOfAttr"> int Number of attributes without class attribute </param>
        /// <param name="capacity"> int Capacity of sample </param>
        /// <returns> empty weka data set </returns>
        private static Instances createEmptyWekaDataSet(int numOfAttr, int capacity, IDictionary <double[], string> classValues)
        {
            //Vector for class attribute possible values
            FastVector fvClassVal = new FastVector();
            //Map double value for every possible class value
            Hashtable classVals = new Dictionary <string, double?>();
            //Map class label with double key value
            Hashtable classValsDoubleAsKey = new Dictionary <double?, string>();
            //ind represents double value for class attribute
            int ind = 0;

            //loop through possible class values
            foreach (KeyValuePair <double[], string> values in classValues)
            {
                //add value to vector
                fvClassVal.addElement(values.Value);

                //map double value for class value
                classVals[values.Value] = new double?(ind);
                //map class label for double key value
                classValsDoubleAsKey[new double?(ind)] = values.Value;

                ind++;
            }
            //Class attribute with possible values
            Attribute classAttribute = new Attribute("theClass", fvClassVal, classValues.Count);
            //Creating attribute vector for Instances class instance
            FastVector fvWekaAttributes = new FastVector(numOfAttr + 1);

            //Fill vector with simple attributes
            for (int i = 0; i < numOfAttr; i++)
            {
                fvWekaAttributes.addElement(new Attribute(i + "", i));
            }
            //Add class attribute to vector
            fvWekaAttributes.addElement(classAttribute);

            //newDataSet as Instances class instance
            Instances newDataSet = new Instances("newDataSet", fvWekaAttributes, capacity);

            return(newDataSet);
        }
예제 #15
0
///
///     <summary> * Sets the format of output instances. </summary>
///
        private void setOutputFormat()
        {
            // give names to the new attributes
            FastVector newAtts = new FastVector();
            string     foName  = null;

            for (int i = 0; i < getInputFormat().numAttributes(); i++)
            {
                string attName = getInputFormat().attribute(i).name();
                foName = "'FT " + attName.Replace('\'', ' ').Trim() + " (re)\'";
                Attribute newAttribX = new Attribute(foName);
                newAtts.addElement(newAttribX);

                foName = "'FT " + attName.Replace('\'', ' ').Trim() + " (im)\'";
                Attribute newAttribY = new Attribute(foName);
                newAtts.addElement(newAttribY);
            }

            setOutputFormat(new Instances(getInputFormat().relationName(), newAtts, getNumCoeffs()));
        }
예제 #16
0
        //code taken from here http://stackoverflow.com/questions/9616872/classification-of-instances-in-weka/14876081#14876081
        // This creates the data set's attributes vector
        public static FastVector CreateFastVector(int size)
        {
            var fv = new FastVector();

            weka.core.Attribute att;

            foreach (int key in TrainingTesting_SharedVariables._trainTopIGFeatures)
            {
                if (key != TrainingTesting_SharedVariables._trainTopIGFeatures[TrainingTesting_SharedVariables._trainTopIGFeatures.Length - 1])
                {
                    att = new weka.core.Attribute("att_" + (key + 1).ToString());
                    fv.addElement(att);
                }
            }

            {
                var           classValues = new FastVector(1); //it doesnt matter if its 3 or 1, when addElement is used the fastvector grows.
                List <string> labels      = GuiPreferences.Instance.getLabels();

                GuiPreferences.Instance.setLog("automatically! adding " + (labels.Count - 1).ToString() + " classes 2 -> " + (labels.Count + 1).ToString() + " to fast vector, based on protocol labels");

                //baseline is ignored, we start from the second event in the protocol
                for (int l = 1; l < labels.Count; l++)
                {
                    classValues.addElement((l + 1).ToString());
                }

                //classValues.addElement("2");
                //classValues.addElement("3");
                //classValues.addElement("4");
                //classValues.addElement("5");
                var classAttribute = new weka.core.Attribute("class", classValues);
                fv.addElement(classAttribute);
            }

            return(fv);
        }
예제 #17
0
        void RebuildCellRenderingLists(BatchedCell cell, Vector3 observerPos, float visibleDistance)
        {
            // rebuild batch lists to be used in the rendering loop
            cell.ClearBatches();

            float cullDistance = (visibleDistance * VoxelPlayEnvironment.CHUNK_SIZE) * (visibleDistance * VoxelPlayEnvironment.CHUNK_SIZE);

            for (int j = 0; j < cell.instancedChunks.count; j++)
            {
                InstancedChunk instancedChunk = cell.instancedChunks.values [j];
                if (instancedChunk == null)
                {
                    continue;
                }

                // check if chunk is in area
                Vector3 chunkCenter = instancedChunk.chunk.position;
                if (FastVector.SqrDistance(ref chunkCenter, ref observerPos) > cullDistance)
                {
                    continue;
                }

                // add instances to batch
                InstancedVoxel[] voxels = instancedChunk.instancedVoxels.values;
                for (int i = 0; i < instancedChunk.instancedVoxels.count; i++)
                {
                    BatchedMesh batchedMesh = voxels [i].batchedMesh;

                    Batch batch = batchedMesh.batches.last;
                    if (batch == null || batch.instancesCount >= Batch.MAX_INSTANCES)
                    {
                        batch = batchedMesh.batches.FetchDirty();
                        if (batch == null)
                        {
                            batch = new Batch();
                            batch.instancedMaterial = GameObject.Instantiate <Material> (batchedMesh.material);
                            if (batchedMesh.voxelDefinition.rotationRandomY || batchedMesh.voxelDefinition.rotation != Misc.vector3zero)
                            {
                                batch.instancedMaterial.EnableKeyword(SKW_VOXELPLAY_USE_ROTATION);
                            }
                            batchedMesh.batches.Add(batch);
                        }
                        batch.Init();
                    }
                    int pos = batch.instancesCount++;
                    batch.positions [pos]   = voxels [i].position;
                    batch.rotations [pos].x = voxels [i].rotation.x; batch.rotations [pos].y = voxels [i].rotation.y; batch.rotations [pos].z = voxels [i].rotation.z; batch.rotations [pos].w = voxels [i].rotation.w;
//						batch.scales[pos] = voxels[i].scale;
                    batch.colorsAndLight [pos].x = voxels [i].color.r / 255f;
                    batch.colorsAndLight [pos].y = voxels [i].color.g / 255f;
                    batch.colorsAndLight [pos].z = voxels [i].color.b / 255f;
                    batch.colorsAndLight [pos].w = voxels [i].packedLight;
                    batch.UpdateBounds(voxels [i].position, voxels [i].meshSize);
                }
            }

            for (int i = 0; i <= cell.batchedMeshes.lastIndex; i++)
            {
                BatchedMesh batchedMesh = cell.batchedMeshes.values [i];
                if (batchedMesh == null)
                {
                    continue;
                }
                for (int j = 0; j < batchedMesh.batches.count; j++)
                {
                    Batch batch = batchedMesh.batches.values [j];
                    batch.ComputeBounds();
                    // Set positions
                    batch.positionsBuffer.SetData(batch.positions);
                    batch.instancedMaterial.SetBuffer("_Positions", batch.positionsBuffer);
                    // Set colors and light
                    batch.colorsAndLightBuffer.SetData(batch.colorsAndLight);
                    batch.instancedMaterial.SetBuffer("_ColorsAndLight", batch.colorsAndLightBuffer);
                    // Set rotations
                    batch.rotationsBuffer.SetData(batch.rotations);
                    batch.instancedMaterial.SetBuffer("_Rotations", batch.rotationsBuffer);
                    // Set buffer args
                    Mesh mesh = batchedMesh.voxelDefinition.mesh;
                    batch.args [0] = mesh.GetIndexCount(0);
                    batch.args [1] = (uint)batch.instancesCount;
                    batch.args [2] = mesh.GetIndexStart(0);
                    batch.args [3] = 0;                     // (uint)mesh.GetBaseVertex (0);
                    batch.argsBuffer.SetData(batch.args);
                }
            }
        }
        public void LearnModel()
        {
            Init();
            foreach (Feature currFeature in DomPool.SelectorFeatures)
            {
                String             featureString = currFeature.ToString();
                HashSet <HtmlNode> resNodes      = DomPool.RunXpathQuery(featureString);
                foreach (HtmlNode nd in resNodes)
                {
                    if (!allNodes.Contains(nd))
                    {
                        continue;
                    }
                    nodeFeatures[nd].Add(featureString);
                }
            }

            FastVector fvWekaAttributes = GetDataSetAtts();
            Instances  trainingSet      = new Instances("TS", fvWekaAttributes, 100);

            trainingSet.setClassIndex(fvWekaAttributes.size() - 1);

            foreach (HtmlNode currNode in allNodes)
            {
                Instance item = new SparseInstance(fvWekaAttributes.size());

                for (int i = 0; i < fvWekaAttributes.size() - 1; i++)
                {
                    weka.core.Attribute currFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(i);
                    if (nodeFeatures[currNode].Contains(currFeature.name()))
                    {
                        item.setValue(currFeature, 1);
                    }
                    else
                    {
                        item.setValue(currFeature, 0);
                    }
                }

                //set the class
                weka.core.Attribute classFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(fvWekaAttributes.size() - 1);
                item.setValue(classFeature, (DomPool.TargetNodes.Contains(currNode)?"yes":"no"));
                item.setDataset(trainingSet);
                if (DomPool.TargetNodes.Contains(currNode))
                {
                    for (int t = 0; t < (DomPool.NonTargetNodes.Count() / DomPool.TargetNodes.Count()); t++)
                    {
                        trainingSet.add(new SparseInstance(item));
                    }
                }
                else
                {
                    trainingSet.add(item);
                }
            }

            String[] options = new String[2];
            options[0] = "-C";                 // unpruned tree
            options[1] = "0.1";
            J48 tree = new J48();              // new instance of tree

            tree.setOptions(options);          // set the options
            tree.buildClassifier(trainingSet); // build classifier
            //save the resulting classifier
            classifierTree = tree;

            Reader    treeDot   = new StringReader(tree.graph());
            TreeBuild treeBuild = new TreeBuild();
            Node      treeRoot  = treeBuild.create(treeDot);

            FeaturesUsed = getTreeFeatures(treeRoot);
        }
        void RebuildZoneRenderingLists(Vector3 observerPos, float visibleDistance)
        {
            // rebuild batch lists to be used in the rendering loop
            for (int k = 0; k < batchedMeshes.count; k++)
            {
                BatchedMesh batchedMesh = batchedMeshes.values [k];
                batchedMesh.batches.Clear();
            }

            float cullDistance = (visibleDistance * VoxelPlayEnvironment.CHUNK_SIZE) * (visibleDistance * VoxelPlayEnvironment.CHUNK_SIZE);

            for (int j = 0; j <= instancedChunks.lastIndex; j++)
            {
                InstancedChunk instancedChunk = instancedChunks.values [j];
                if (instancedChunk == null)
                {
                    continue;
                }
                // check if chunk is in area
                Vector3 chunkCenter = instancedChunk.chunk.position;
                if (FastVector.SqrDistance(ref chunkCenter, ref observerPos) > cullDistance)
                {
                    continue;
                }

                // add instances to batch
                InstancedVoxel[] voxels = instancedChunk.instancedVoxels.values;
                for (int i = 0; i < instancedChunk.instancedVoxels.count; i++)
                {
                    VoxelDefinition vd          = voxels [i].voxelDefinition;
                    BatchedMesh     batchedMesh = batchedMeshes.values [vd.batchedIndex];
                    Batch           batch       = batchedMesh.batches.last;
                    if (batch == null || batch.instancesCount >= Batch.MAX_INSTANCES)
                    {
                        batch = batchedMesh.batches.FetchDirty();
                        if (batch == null)
                        {
                            batch = new Batch();
                            batchedMesh.batches.Add(batch);
                        }
                        batch.Init();
                    }
                    int pos = batch.instancesCount++;
                    // just copying the matrix triggers lot of expensive memcpy() calls so we directly copy the fields
//					batch.matrices[pos] = voxels[i].matrix;
                    batch.matrices [pos].m00 = voxels [i].matrix.m00; batch.matrices [pos].m01 = voxels [i].matrix.m01; batch.matrices [pos].m02 = voxels [i].matrix.m02; batch.matrices [pos].m03 = voxels [i].matrix.m03;
                    batch.matrices [pos].m10 = voxels [i].matrix.m10; batch.matrices [pos].m11 = voxels [i].matrix.m11; batch.matrices [pos].m12 = voxels [i].matrix.m12; batch.matrices [pos].m13 = voxels [i].matrix.m13;
                    batch.matrices [pos].m20 = voxels [i].matrix.m20; batch.matrices [pos].m21 = voxels [i].matrix.m21; batch.matrices [pos].m22 = voxels [i].matrix.m22; batch.matrices [pos].m23 = voxels [i].matrix.m23;
                    batch.matrices [pos].m30 = voxels [i].matrix.m30; batch.matrices [pos].m31 = voxels [i].matrix.m31; batch.matrices [pos].m32 = voxels [i].matrix.m32; batch.matrices [pos].m33 = voxels [i].matrix.m33;

                    batch.colorsAndLight [pos].x = voxels [i].color.r / 255f;
                    batch.colorsAndLight [pos].y = voxels [i].color.g / 255f;
                    batch.colorsAndLight [pos].z = voxels [i].color.b / 255f;
                    batch.colorsAndLight [pos].w = voxels [i].packedLight;
                    batch.UpdateBounds(voxels[i].position, voxels[i].meshSize);
                }
            }

            for (int k = 0; k < batchedMeshes.count; k++)
            {
                BatchedMesh batchedMesh = batchedMeshes.values [k];
                for (int j = 0; j < batchedMesh.batches.count; j++)
                {
                    Batch batch = batchedMesh.batches.values [j];
                    batch.materialPropertyBlock.SetVectorArray("_TintColor", batch.colorsAndLight);
                }
            }
        }
예제 #20
0
        public void LearnModel()
        {
            Init();
            foreach (Feature currFeature in DomPool.SelectorFeatures)
            {
                String             featureString = currFeature.ToString();
                HashSet <HtmlNode> resNodes      = DomPool.RunXpathQuery(featureString);
                foreach (HtmlNode nd in resNodes)
                {
                    if (!allNodes.Contains(nd))
                    {
                        continue;
                    }
                    nodeFeatures[nd].Add(featureString);
                }
            }
            FastVector fvWekaAttributes = GetDataSetAtts();
            Instances  trainingSet      = new Instances("TS", fvWekaAttributes, 10);

            trainingSet.setClassIndex(fvWekaAttributes.size() - 1);

            foreach (HtmlNode currNode in allNodes)
            {
                Instance item = new SparseInstance(fvWekaAttributes.size());

                for (int i = 0; i < fvWekaAttributes.size() - 1; i++)
                {
                    weka.core.Attribute currFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(i);
                    if (nodeFeatures[currNode].Contains(currFeature.name()))
                    {
                        item.setValue(currFeature, 1);
                    }
                    else
                    {
                        item.setValue(currFeature, 0);
                    }
                }

                //set the class
                weka.core.Attribute classFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(fvWekaAttributes.size() - 1);
                item.setValue(classFeature, (DomPool.TargetNodes.Contains(currNode)?"yes":"no"));
                item.setDataset(trainingSet);
                if (DomPool.TargetNodes.Contains(currNode))
                {
                    for (int t = 0; t < (DomPool.NonTargetNodes.Count() / DomPool.TargetNodes.Count()); t++)
                    {
                        trainingSet.add(new SparseInstance(item));
                    }
                }
                else
                {
                    trainingSet.add(item);
                }
            }

            //String[] options = new String[2];
            //options = new string[] { "-C", "0.05" };            // unpruned tree
            NaiveBayes cls = new NaiveBayes();         // new instance of tree

            //cls.setOptions(weka.core.Utils.splitOptions("-C 1.0 -L 0.0010 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
            //cls.setOptions(options);     // set the options
            cls.buildClassifier(trainingSet);  // build classifier
            //save the resulting classifier
            classifier = cls;

            //  Reader treeDot = new StringReader(tree.graph());
            //  TreeBuild treeBuild = new TreeBuild();
            //  Node treeRoot = treeBuild.create(treeDot);
            FeaturesUsed = new HashSet <string>();

            foreach (Feature f in DomPool.SelectorFeatures)
            {
                FeaturesUsed.Add(f.ToString());
            }
        }
예제 #21
0
파일: Diabetes.cs 프로젝트: gitzfibbon/ml
        // Define all the attributes for the diabetes dataset
        private static Instances DefineCategoricalAttributes()
        {
            FastVector attributes = new FastVector();

            FastVector numberOfTimesPregnant = new FastVector();

            numberOfTimesPregnant.addElement("zero");   // 0
            numberOfTimesPregnant.addElement("low");    // 1-4
            numberOfTimesPregnant.addElement("medium"); // 5-9
            numberOfTimesPregnant.addElement("high");   // 10+
            attributes.addElement(new weka.core.Attribute("numberOfTimesPregnant", numberOfTimesPregnant));

            FastVector plasmaGlucoseConcentration = new FastVector();

            plasmaGlucoseConcentration.addElement("normal"); // < 140
            plasmaGlucoseConcentration.addElement("high");   // >= 140
            attributes.addElement(new weka.core.Attribute("plasmaGlucoseConcentration", plasmaGlucoseConcentration));

            FastVector diastolicBloodPressure = new FastVector();

            diastolicBloodPressure.addElement("low");      // < 60
            diastolicBloodPressure.addElement("normal");   // 60 to 79
            diastolicBloodPressure.addElement("pre-high"); // 80 to 89
            diastolicBloodPressure.addElement("high");     // 90+
            attributes.addElement(new weka.core.Attribute("diastolicBloodPressure", diastolicBloodPressure));

            FastVector tricepsSkinFoldThickness = new FastVector();

            tricepsSkinFoldThickness.addElement("low");    // < 4.5
            tricepsSkinFoldThickness.addElement("normal"); // 4.5 to 36.5
            tricepsSkinFoldThickness.addElement("high");   // > 36.5
            attributes.addElement(new weka.core.Attribute("tricepsSkinFoldThickness", tricepsSkinFoldThickness));

            FastVector twoHourSerumInsulin = new FastVector();

            twoHourSerumInsulin.addElement("normal"); // < 166
            twoHourSerumInsulin.addElement("high");   // >= 166
            attributes.addElement(new weka.core.Attribute("twoHourSerumInsulin", twoHourSerumInsulin));

            FastVector bmi = new FastVector();

            bmi.addElement("underweight"); // < 18.5
            bmi.addElement("normal");      // 18.5 to 25
            bmi.addElement("overweight");  // 25 to 30
            bmi.addElement("obese");       // 30+
            attributes.addElement(new weka.core.Attribute("bmi", bmi));

            FastVector diabetesPedigreeFunction = new FastVector();

            diabetesPedigreeFunction.addElement("low");    // < 0.2
            diabetesPedigreeFunction.addElement("normal"); // 0.2 to 0.7
            diabetesPedigreeFunction.addElement("high");   // > 0.7
            attributes.addElement(new weka.core.Attribute("diabetesPedigreeFunction", diabetesPedigreeFunction));

            FastVector age = new FastVector();

            age.addElement("young");  // under 30
            age.addElement("middle"); // 30 to 50 inclusive
            age.addElement("old");    // over 50
            attributes.addElement(new weka.core.Attribute("age", age));

            FastVector diabetes = new FastVector();

            diabetes.addElement("0"); // negative
            diabetes.addElement("1"); // positive
            attributes.addElement(new weka.core.Attribute("diagnosis", diabetes));

            Instances instances = new Instances("diabetes", attributes, 0);

            return(instances);
        }