Exemple #1
0
            public override void Execute()
            {
                String word;

                if (Owner.InputNumber != null)
                {
                    Owner.InputNumber.SafeCopyToHost();
                    word = Owner.InputNumber.Host[0].ToString("F8");
                }
                else
                {
                    word = Text;
                }



                String padded = word.PadRight(Owner.TextWidth);

                if (ConvertToUpperCase)
                {
                    padded = padded.ToUpper();
                    //MyLog.DEBUG.WriteLine("text: " + padded);
                }

                if (Padding == MyStringConversionsClass.PaddingSchemes.Repeat)
                {
                    padded = MyStringConversionsClass.RepeatWord(padded, Owner.TextWidth);
                }
                else if (Padding == MyStringConversionsClass.PaddingSchemes.Stretch)
                {
                    padded = MyStringConversionsClass.StretchWord(padded, Owner.TextWidth);
                }


                for (int i = 0; i < Owner.TextWidth; i++)
                {
                    if (Encoding == MyStringConversionsClass.StringEncodings.DigitIndexes)
                    {
                        Owner.Output.Host[i] = MyStringConversionsClass.StringToDigitIndexes(padded[i]);
                    }
                    else
                    {
                        Owner.Output.Host[i] = MyStringConversionsClass.StringToUvscCoding(padded[i]);
                    }
                }

                Owner.Output.SafeCopyToDevice();
            }
Exemple #2
0
        protected override void Execute()
        {
            if (m_lowerThreshold >= m_upperThreshold)
            {
                MyLog.ERROR.WriteLine("MyVectorTextObserver - LowerThreshold needs to be lower than UpperThreshold.");
            }


            //clear screen
            Clear();



            Target.Data.SafeCopyToHost();
            Target.Weights.SafeCopyToHost();



            float[] weights = Target.Weights.Host;
            int[]   indexes = new int[weights.Length];
            for (int i = 0; i < weights.Length; i++)
            {
                indexes[i] = i;
            }

            if (SortByWeights)
            {
                Array.Sort(Target.Weights.Host, indexes);
                Array.Reverse(Target.Weights.Host);
                Array.Reverse(indexes);
            }


            int m_numberOfRows = Target.Data.Count / Target.Data.ColumnHint;

            if (m_numberOfRows > m_Rows)
            {
                m_numberOfRows = m_Rows;
            }
            if (m_numberOfRows > Target.Weights.Count)
            {
                m_numberOfRows = Target.Weights.Count;
            }



            bool displayedWarning = false;

            for (int i = 0; i < m_numberOfRows; i++)
            {
                if (Target.Weights.Host[i] <= m_lowerThreshold)
                {
                    continue;
                }

                int WeightsStringLength = 0;
                if (m_printWeights) //weights have to be printed in front of the concepts
                {
                    string WeigthsString = Target.Weights.Host[i].ToString("F2") + " ";
                    WeightsStringLength = WeigthsString.Length;

                    for (int j = 0; j < WeightsStringLength; j++)
                    {
                        m_deviceBuffer[i * m_cols + j] = MyStringConversionsClass.StringToDigitIndexes(WeigthsString[j]);
                    }

                    // MyLog.DEBUG.WriteLine("wText : " + WeigthsString);
                }


                int numberOfColumns = Target.Data.ColumnHint;
                int windowWidth     = m_cols - WeightsStringLength;
                if (numberOfColumns > windowWidth)
                {
                    if (!displayedWarning)
                    {
                        MyLog.WARNING.WriteLine("Text lines (length " + numberOfColumns + ") cannot fit into MyVectorTextObserver window width (" + windowWidth + "), they will be cropped.");
                        displayedWarning = true;
                    }
                    numberOfColumns = windowWidth;
                }


                for (int j = 0; j < numberOfColumns; j++)
                {
                    if (Target.Encoding == MyStringConversionsClass.StringEncodings.DigitIndexes)
                    {
                        m_deviceBuffer[i * m_cols + j + WeightsStringLength] = Target.Data.Host[indexes[i] * Target.Data.ColumnHint + j];
                    }
                    else
                    {
                        m_deviceBuffer[i * m_cols + j + WeightsStringLength] = MyStringConversionsClass.UvscCodingToDigitIndexes(
                            Target.Data.Host[indexes[i] * Target.Data.ColumnHint + j]);
                    }
                }

                MyDrawStringHelper.DrawStringFromGPUMem(m_deviceBuffer, 0, i * (MyDrawStringHelper.CharacterHeight + 1), 0, ComputeColor(Target.Weights.Host[i]), VBODevicePointer, TextureWidth, TextureHeight, i * m_cols, m_cols);
            }
        }
        public override void Execute()
        {
            if (WriteOnFilePath == null || WriteOnFilePath == "")
            {
                MyLog.WARNING.WriteLine(Owner.Name + ": The Task 'Write On File' is selected, but the specified path for writing on File (FileWritePath) is empty, not writing on file");
            }
            else
            {
                Owner.Data.SafeCopyToHost();
                Owner.Weights.SafeCopyToHost();

                string ReturnDataSplit = "";
                string ReturnData      = "";

                int NumberOfVectors = SplitValue;
                int SplitRange      = Owner.Data.ColumnHint / NumberOfVectors;
                int VectorLength    = Owner.Data.ColumnHint;

                if (ShowDebugInfo)
                {
                    MyLog.DEBUG.WriteLine("Data Length: " + Owner.Data.Host.Length);
                    MyLog.DEBUG.WriteLine("Vector Length: " + VectorLength);
                    MyLog.DEBUG.WriteLine("Number of Vectors: " + NumberOfVectors);
                    MyLog.DEBUG.WriteLine("SplitRange: " + SplitRange);
                    MyLog.DEBUG.WriteLine("Number of entries: " + Owner.Data.Host.Length / Owner.Data.ColumnHint);
                    MyLog.DEBUG.WriteLine("Weights Length: " + Owner.Weights.Host.Length);
                }

                int consecutiveSpaces = 0;
                int spaceChar;

                if (Owner.Encoding == MyStringConversionsClass.StringEncodings.UVSC)
                {
                    spaceChar = MyStringConversionsClass.UvscCodingToDigitIndexes(' ');
                }
                else
                {
                    spaceChar = MyStringConversionsClass.StringToDigitIndexes(' ');
                }

                StringBuilder sb = new StringBuilder();

                for (int z = 0; z < Owner.Data.Host.Length; z++)
                {
                    if (Owner.Data.Host[z] == spaceChar)
                    {
                        consecutiveSpaces++;
                        //end the writing prematurely if there is an empty line (for printing long buffers filled with just a few lines)
                        if (consecutiveSpaces > Owner.Data.ColumnHint)
                        {
                            if (z % Owner.Data.ColumnHint == spaceChar)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        consecutiveSpaces = 0;
                    }

                    if (Owner.Encoding == MyStringConversionsClass.StringEncodings.DigitIndexes)
                    {
                        sb.Append(MyStringConversionsClass.DigitIndexToString(Owner.Data.Host[z]));
                    }
                    else
                    {
                        sb.Append(MyStringConversionsClass.UvscCodingToString(Owner.Data.Host[z]));
                    }
                }


                ReturnData = sb.ToString();
                string        current = "";
                String[]      elements;
                StringBuilder sbSplit = new StringBuilder();


                for (int j = 0; j < ReturnData.Length; j += VectorLength)
                {
                    sbSplit.Append(Math.Round(Owner.Weights.Host[j / VectorLength], 2) + " "); //Round the weight to 2 decimals places

                    for (int n = 0; n < NumberOfVectors; n++)
                    {
                        current = ReturnData.Substring(((j) + (n * (SplitRange))), SplitRange); //Divide chunk depending on the number of vectors
                        //MyLog.DEBUG.WriteLine("Analyzing chunk " + n + ", Substring with index " + ((j) + (n * (SplitRange))) + " with length  " + SplitRange + " = " + current);
                        elements    = Regex.Split(current, @"\s*,\s*");                         //Spliting expression is any number of white spaces, comma, and again any number of white spaces
                        elements[0] = elements[0].Trim();                                       //Trim formats the text so that there are no spaces from the word/s and the beginning and the end of the length
                        sbSplit.Append(elements[0]);

                        if (n != (NumberOfVectors - 1))
                        {
                            sbSplit.Append(",");
                        }
                    }

                    sbSplit.Append(Environment.NewLine);
                }

                ReturnDataSplit = sbSplit.ToString();

                //Convert string to stream
                byte[]       byteArray = Encoding.UTF8.GetBytes(ReturnDataSplit);
                MemoryStream stream    = new MemoryStream(byteArray);
                StreamReader reader    = new StreamReader(stream);

                //Before writing on file, delete specific lines from the stream, the lines containing the string ",,", because they contain incomplete information
                string        search_text = ",,";
                string        old;
                StringBuilder sbNo         = new StringBuilder();
                StreamReader  sr           = reader;
                int           DeletedLines = 0;

                while ((old = sr.ReadLine()) != null)
                {
                    if (!old.Contains(search_text))
                    {
                        sbNo.Append(old);
                        sbNo.Append(Environment.NewLine);
                    }
                    else
                    {
                        DeletedLines++;
                    }
                }

                sr.Close();
                string FormattedResult = sbNo.ToString();
                File.WriteAllText(WriteOnFilePath, FormattedResult);

                if (ShowDebugInfo)
                {
                    MyLog.DEBUG.WriteLine("OutPut: " + Environment.NewLine + FormattedResult);
                    MyLog.DEBUG.WriteLine("Number of lines that were deleted during the process because they contained the charachter ',,' = " + DeletedLines);
                }
            }
        }
Exemple #4
0
            public override void Execute()
            {
                // ReadFinishedSignal should be active only one time step
                if (Owner.ReadFinishedSignal.IsRised())
                {
                    Owner.ReadFinishedSignal.Drop();
                }

                if (SimulationStep % Owner.ReadingFrequency == 0)
                {
                    long id = SimulationStep / Owner.ReadingFrequency;

                    if (Owner.m_parsedText == null)
                    {
                        MyLog.ERROR.WriteLine("No input data for MyAssociationWorld!");
                        return;
                    }

                    // let others know that reading has finished
                    if (id == Owner.m_parsedText.Length)
                    {
                        Owner.ReadInProgressSignal.Drop();
                        Owner.ReadFinishedSignal.Raise();
                    }

                    id = id % Owner.m_parsedText.Length;

                    //   MyLog.DEBUG.WriteLine("Id = " + id + " / " + Owner.m_parsedText.Length);
                    // MyLog.DEBUG.WriteLine("str = " + Owner.m_parsedText[id]);

                    String[] elements = Regex.Split(Owner.m_parsedText[id], @"\s*,\s*"); //spliting expression is any number of white spaces, comma, and again any number of white spaces

                    if (elements.Length < 3 || elements.Length > 4)
                    {
                        string message;
                        if (elements.Length < 3)
                        {
                            message = "few";
                        }
                        else
                        {
                            message = "many";
                        }

                        MyLog.WARNING.WriteLine("Too " + message + " (" + elements.Length + " instead of 3 or 4) elements in input line '" + Owner.m_parsedText[id] + "' for " + Owner.Name + ". Output will be empty.");
                        return;
                    }


                    MyLog.DEBUG.WriteLine("Id = " + id + " / " + Owner.m_parsedText.Length);
                    MyLog.DEBUG.WriteLine("conc1 = " + elements[0]);
                    MyLog.DEBUG.WriteLine("conc2 = " + elements[1]);
                    MyLog.DEBUG.WriteLine("relation = " + elements[2]);

                    if (elements.Length == 3) //input file does not contain relation strength
                    {
                        Owner.RelationStrength.Host[0] = 1.0f;
                    }
                    else
                    {
                        try
                        {
                            Owner.RelationStrength.Host[0] = float.Parse(elements[3]);
                        }
                        catch
                        {
                            MyLog.WARNING.WriteLine(Owner.Name + " expects the fourth element in the input line '" + Owner.m_parsedText[id] + "' to be a number.");
                            Owner.RelationStrength.Host[0] = float.NaN;
                        }
                    }
                    MyLog.DEBUG.WriteLine("relation strength = " + Owner.RelationStrength.Host[0]);


                    String elem1 = elements[0].PadRight(Owner.TextWidth);
                    String elem2 = elements[1].PadRight(Owner.TextWidth);
                    String rel   = elements[2].PadRight(Owner.TextWidth);


                    for (int i = 0; i < Owner.TextWidth; i++)
                    {
                        Owner.Concept1.Host[i] = MyStringConversionsClass.StringToDigitIndexes(elem1[i]);
                        Owner.Concept2.Host[i] = MyStringConversionsClass.StringToDigitIndexes(elem2[i]);
                        Owner.Relation.Host[i] = MyStringConversionsClass.StringToDigitIndexes(rel[i]);
                    }

                    Owner.Concept1.SafeCopyToDevice();
                    Owner.Concept2.SafeCopyToDevice();
                    Owner.Relation.SafeCopyToDevice();

                    // MyLog.DEBUG.WriteLine("CCC_" + concept + "_CCC");

                    Owner.RelationStrength.SafeCopyToDevice();
                }
            }