コード例 #1
0
        protected override void Reset()
        {
            List <String> actions = Target.GetActionLabels();

            m_StringDeviceBuffer = new CudaDeviceVariable <float>(1000);
            m_StringDeviceBuffer.Memset(0);

            if (numOfActions < actions.Count)
            {
                if (m_actionLabels != null)
                {
                    m_actionLabels.Dispose();
                }

                m_actionLabels = new CudaDeviceVariable <uint>(actions.Count * LABEL_PIXEL_WIDTH * LABEL_PIXEL_WIDTH);
                m_actionLabels.Memset(0);

                for (int i = 0; i < actions.Count; i++)
                {
                    MyDrawStringHelper.String2Index(actions[i], m_StringDeviceBuffer);
                    MyDrawStringHelper.DrawStringFromGPUMem(
                        m_StringDeviceBuffer, i * LABEL_PIXEL_WIDTH + 5, 8, 0, 0xFFFFFFFF,
                        m_actionLabels.DevicePointer, LABEL_PIXEL_WIDTH * actions.Count, LABEL_PIXEL_WIDTH, 0, actions[i].Length);
                }

                numOfActions = actions.Count;
            }
            Target.ReadTwoDimensions(ref m_qMatrix, ref m_qMatrixActions, XAxisVariableIndex, YAxisVariableIndex, ApplyInnerScaling);

            if (MatrixSizeOK())
            {
                DrawDataToGpu();
            }
        }
コード例 #2
0
        protected override void Reset()
        {
            List <MyMotivatedAction> actions = Target.Rds.ActionManager.Actions;

            if (numOfActions < actions.Count)
            {
                if (m_actionLabels != null)
                {
                    m_actionLabels.Dispose();
                }

                m_actionLabels = new CudaDeviceVariable <uint>(actions.Count * LABEL_PIXEL_WIDTH * LABEL_PIXEL_WIDTH);
                m_actionLabels.Memset(0);

                for (int i = 0; i < actions.Count; i++)
                {
                    MyDrawStringHelper.DrawString(actions[i].GetLabel(), i * LABEL_PIXEL_WIDTH + 5, 8, 0, 0xFFFFFFFF, m_actionLabels.DevicePointer, LABEL_PIXEL_WIDTH * actions.Count, LABEL_PIXEL_WIDTH);
                }

                numOfActions = actions.Count;
            }
            Target.Vis.ReadTwoDimensions(ref m_qMatrix, ref m_qMatrixActions, XAxisVariableIndex, YAxisVariableIndex, ShowCurrentMotivations);

            if (MatrixSizeOK())
            {
                DrawDataToGpu();
            }
        }
コード例 #3
0
        protected override void Execute()
        {
            m_kernel_drawEdges.GridDimensions  = new dim3(Target.PatchesNum);
            m_kernel_drawEdges.BlockDimensions = new dim3(Target.PatchesNum);
            m_kernel_fillImWhite.SetupExecution(Target.MaskCount);
            m_kernel_fillImFromIm.SetupExecution(Target.MaskCount);

            m_kernel_fillImFromIm.Run(VBODevicePointer, Target.OutMask, TextureWidth * TextureHeight, 5);//(int)Target.PatchesNum /5);



            switch (ObserverMode)
            {
            case MyJoinPatObsMode.Graph:
                //. print edges
                m_kernel_drawEdges.Run(VBODevicePointer, TextureWidth, Target.AdjMatrix, Target.Patches, Target.PatchesNum, Target.PatchesDim, Target.Desc, Target.Desc.ColumnHint, 0);
                break;

            case MyJoinPatObsMode.GraphWeights:
                //. print weight of graph's edges
                m_kernel_fillImWhite.Run(VBODevicePointer, TextureWidth, TextureHeight);
                m_kernel_drawEdges.Run(VBODevicePointer, TextureWidth, Target.AdjMatrix, Target.Patches, Target.PatchesNum, Target.PatchesDim, Target.Desc, Target.Desc.ColumnHint, 1);
                break;

            case MyJoinPatObsMode.MaskId:
                //. print ids to objects
                Target.OutPatches.SafeCopyToHost();
                for (int i = 0; i < Math.Min(Target.PatchesNum, 10); i++)
                {
                    int x = (int)Target.OutPatches.Host[i * Target.PatchesDim];
                    int y = (int)Target.OutPatches.Host[i * Target.PatchesDim + 1];
                    MyDrawStringHelper.String2Index(i.ToString(), m_StringDeviceBuffer);
                    MyDrawStringHelper.DrawStringFromGPUMem(m_StringDeviceBuffer, x, y, (uint)Color.White.ToArgb(), (uint)Color.Black.ToArgb(), VBODevicePointer, TextureWidth, TextureHeight, 0, i.ToString().Length);
                }
                break;

            case MyJoinPatObsMode.Desc:
                // find the max value
                Target.Desc.SafeCopyToHost();
                float maxValue = float.MinValue;
                float minValue = float.MaxValue;
                for (int i = 0; i < Target.Desc.Count; i++)
                {
                    maxValue = (Target.Desc.Host[i] > maxValue) ? Target.Desc.Host[i] : maxValue;
                    minValue = (Target.Desc.Host[i] < minValue) ? Target.Desc.Host[i] : minValue;
                }
                maxValue = maxValue - minValue;
                // draw first row in desc :)
                m_kernel_drawDesc.SetupExecution(Target.MaskCount);
                m_kernel_drawDesc.Run(VBODevicePointer, Target.Mask, TextureWidth * TextureHeight, Target.Desc, maxValue, minValue);
                break;
            }
        }
コード例 #4
0
        protected override void Execute()
        {
            m_kernel.SetupExecution(Target.AttentionMap.Count);
            m_kernel.Run(Target.AttentionMap, Target.Centroids, Target.CentroidsCount, TextureWidth, TextureHeight, VBODevicePointer);

            for (int i = 0; i < Target.CentroidsCount; i++)
            {
                int   x   = (int)((Target.Centroids.Host[i * MyPupilControl.CENTROID_FIELDS] + 1) * 0.5f * TextureWidth);
                int   y   = (int)((Target.Centroids.Host[i * MyPupilControl.CENTROID_FIELDS + 1] + 1) * 0.5f * TextureHeight);
                float DBI = Target.Centroids.Host[i * MyPupilControl.CENTROID_FIELDS + 5];
                MyDrawStringHelper.DrawString(i + " ", x - 4, y - 14, 0, 0xFF69A5FF, VBODevicePointer, TextureWidth, TextureHeight);
                //MyDrawStringHelper.DrawDecimalString(DBI.ToString("0.0000") , x - 10, y + 2, 0, 0xFF69A5FF, VBODevicePointer, TextureWidth, TextureHeight);
            }
        }
コード例 #5
0
        protected override void Execute()
        {
            if (m_qMatrix != null)
            {
                m_kernel.SetupExecution(TextureWidth * TextureHeight);
                m_kernel.Run(m_plotValues.DevicePointer, m_actionIndices.DevicePointer, m_actionLabels.DevicePointer, numOfActions, LABEL_PIXEL_WIDTH, LABEL_PIXEL_WIDTH, 0f, MaxQValue, m_qMatrix.GetLength(0), m_qMatrix.GetLength(1), VBODevicePointer);

                if (ViewMode == ViewMethod.Orbit_3D)
                {
                    m_vertexKernel.SetupExecution(m_qMatrix.Length);
                    m_vertexKernel.Run(m_plotValues.DevicePointer, 0.1f, m_qMatrix.GetLength(0), m_qMatrix.GetLength(1), MaxQValue, VertexVBODevicePointer);
                }
            }

            float[,] lastQMatrix = m_qMatrix;

            MyStochasticReturnPredictor srp = null;

            if (AbstractActionIndex < Target.Rds.VarManager.MAX_VARIABLES)
            {
                srp = (MyStochasticReturnPredictor)Target.Vis.GetPredictorNo(AbstractActionIndex);
            }

            if (srp != null)
            {
                Target.Vis.ReadTwoDimensions(ref m_qMatrix, ref m_qMatrixActions, srp, XAxisVariableIndex, YAxisVariableIndex, ShowCurrentMotivations);
            }

            if (lastQMatrix != m_qMatrix)
            {
                TriggerReset();
            }
            else if (m_qMatrix != null && MatrixSizeOK())
            {
                m_plotValues.CopyToDevice(m_qMatrix);
                m_actionIndices.CopyToDevice(m_qMatrixActions);

                if (ShowSRPNames && srp != null)
                {
                    //Set texture size, it will trigger texture buffer reallocation
                    TextureWidth  = LABEL_PIXEL_WIDTH * m_qMatrix.GetLength(0);
                    TextureHeight = LABEL_PIXEL_WIDTH * m_qMatrix.GetLength(1);

                    String label = srp.GetLabel() + " M:" + srp.GetMyTotalMotivation();

                    MyDrawStringHelper.DrawString(label, 0, 0, 0, 0x999999, VBODevicePointer, TextureWidth, TextureHeight);
                }
            }
        }
コード例 #6
0
        protected override void Reset()
        {
            m_StringDeviceBuffer = new CudaDeviceVariable <float>(1000);
            m_StringDeviceBuffer.Memset(0);

            List <String> actions = Target.GetActionLabels();

            if (numOfActions < actions.Count)
            {
                if (m_actionLabels != null)
                {
                    m_actionLabels.Dispose();
                }

                m_actionLabels = new CudaDeviceVariable <uint>(actions.Count * LABEL_PIXEL_WIDTH * LABEL_PIXEL_WIDTH);
                m_actionLabels.Memset(0);

                for (int i = 0; i < actions.Count; i++)
                {
                    MyDrawStringHelper.String2Index(actions[i], m_StringDeviceBuffer);
                    MyDrawStringHelper.DrawStringFromGPUMem(m_StringDeviceBuffer, i * LABEL_PIXEL_WIDTH + 5, 8, 0, 0xFFFFFFFF, m_actionLabels.DevicePointer, LABEL_PIXEL_WIDTH * actions.Count, LABEL_PIXEL_WIDTH, 0, actions[i].Length);
                }

                numOfActions = actions.Count;
            }

            MyStochasticReturnPredictor srp = null;

            srp = (MyStochasticReturnPredictor)Target.Vis.GetPredictorNo(AbstractActionIndex);

            if (srp == null)
            {
                m_qMatrix     = null;
                TextureWidth  = 0;
                TextureHeight = 0;
            }
            else
            {
                Target.ReadTwoDimensions(ref m_qMatrix, ref m_qMatrixActions, XAxisVariableIndex, YAxisVariableIndex, ApplyInnerScaling, AbstractActionIndex);

                if (MatrixSizeOK())
                {
                    DrawDataToGpu();
                }
            }
        }
コード例 #7
0
        protected override void Reset()
        {
            List <MyMotivatedAction> actions = Target.Rds.ActionManager.Actions;

            if (numOfActions < actions.Count)
            {
                if (m_actionLabels != null)
                {
                    m_actionLabels.Dispose();
                }

                m_actionLabels = new CudaDeviceVariable <uint>(actions.Count * LABEL_PIXEL_WIDTH * LABEL_PIXEL_WIDTH);
                m_actionLabels.Memset(0);

                for (int i = 0; i < actions.Count; i++)
                {
                    MyDrawStringHelper.DrawString(actions[i].GetLabel(), i * LABEL_PIXEL_WIDTH + 5, 8, 0, 0xFFFFFFFF, m_actionLabels.DevicePointer, LABEL_PIXEL_WIDTH * actions.Count, LABEL_PIXEL_WIDTH);
                }

                numOfActions = actions.Count;
            }

            MyStochasticReturnPredictor srp = null;

            if (AbstractActionIndex < Target.Rds.VarManager.MAX_VARIABLES)
            {
                srp = (MyStochasticReturnPredictor)Target.Vis.GetPredictorNo(AbstractActionIndex);
            }

            if (srp == null)
            {
                m_qMatrix     = null;
                TextureWidth  = 0;
                TextureHeight = 0;
            }
            else
            {
                Target.Vis.ReadTwoDimensions(ref m_qMatrix, ref m_qMatrixActions, srp, XAxisVariableIndex, YAxisVariableIndex, ShowCurrentMotivations);
                if (MatrixSizeOK())
                {
                    DrawDataToGpu();
                }
            }
        }
コード例 #8
0
        private void drawCoordinates()
        {
            m_canvas.Memset(COLOR_BACKGROUND);

            // Ordinates
            double range            = m_plotCurrentValueMax - m_plotCurrentValueMin;
            double scale            = Math.Floor(Math.Log10(range));
            double unit             = Math.Pow(10, scale) / 2;
            int    displayPrecision = (scale >= 1) ? 0 : (1 - (int)scale);
            double firstOrdinate    = Math.Ceiling(m_plotCurrentValueMin / unit) * unit;

            for (int n = 0; firstOrdinate + n * unit < m_plotCurrentValueMax; n++)
            {
                double value    = firstOrdinate + n * unit;
                string valueStr = string.Format("{0,8:N" + displayPrecision + "}", value);
                double y        = TextureHeight - m_plotAreaOffsetY - m_plotAreaHeight * (value - m_plotCurrentValueMin) / range - MyDrawStringHelper.CharacterHeight / 2;
                MyDrawStringHelper.DrawString(valueStr, 0, (int)y, COLOR_BACKGROUND, COLOR_FONT, VBODevicePointer, TextureWidth, TextureHeight);
            }
        }
コード例 #9
0
        protected override void Execute()
        {
            m_kernel_drawEdges.GridDimensions  = new dim3(Target.PatchesNum);
            m_kernel_drawEdges.BlockDimensions = new dim3(Target.PatchesNum);
            m_kernel_fillImWhite.SetupExecution(Target.MaskCount);
            m_kernel_fillImFromIm.SetupExecution(Target.MaskCount);

            m_kernel_fillImFromIm.Run(VBODevicePointer, Target.OutMask, TextureWidth * TextureHeight, 5);//(int)Target.PatchesNum /5);



            switch (ObserverMode)
            {
            case MyJoinPatObsMode.Graph:
                //. print edges
                m_kernel_drawEdges.Run(VBODevicePointer, TextureWidth, Target.AdjMatrix, Target.Patches, Target.PatchesNum, Target.PatchesDim, Target.Desc, Target.Desc.ColumnHint, 0);
                break;

            case MyJoinPatObsMode.GraphWeights:
                //. print weight of graph's edges
                m_kernel_fillImWhite.Run(VBODevicePointer, TextureWidth, TextureHeight);
                m_kernel_drawEdges.Run(VBODevicePointer, TextureWidth, Target.AdjMatrix, Target.Patches, Target.PatchesNum, Target.PatchesDim, Target.Desc, Target.Desc.ColumnHint, 1);
                break;

            case MyJoinPatObsMode.MaskId:
                //. print ids to objects
                Target.OutPatches.SafeCopyToHost();
                for (int i = 0; i < Math.Min(Target.PatchesNum, 10); i++)
                {
                    int x = (int)Target.OutPatches.Host[i * Target.PatchesDim];
                    int y = (int)Target.OutPatches.Host[i * Target.PatchesDim + 1];
                    MyDrawStringHelper.DrawString(i.ToString(), x, y, (uint)Color.White.ToArgb(), (uint)Color.Black.ToArgb(), VBODevicePointer, TextureWidth, TextureHeight);
                }
                break;
            }
        }
コード例 #10
0
        protected override void Execute()
        {
            // Clear screen on simulation start
            if (!isScreenClear)
            {
                Clear();
                isScreenClear = true;
            }

            //we are able to represent all characters from ' ' (space) to '~' (tilda) and new-line
            int desiredNum = '~' - ' ' + 2; // the last character is \n

            MyMemoryBlock <float> target = (MyMemoryBlock <float>)Target;

            if (target != null)
            {
                //get data to cpu
                Target.SafeCopyToHost();

                //allow inputs that are different in size, only clamp it if neccessary
                int size = Math.Min(target.Host.Length, desiredNum);

                //find max value for character
                int   idx    = 0;
                float maxVal = target.Host[0];
                for (int i = 1; i < size; ++i)
                {
                    if (target.Host[idx] < target.Host[i])
                    {
                        idx = i;
                    }
                }

                //reconstruct a character
                char newChar = '\n';
                if (idx + 1 != desiredNum)
                {
                    newChar = (char)(' ' + idx);
                }

                bool splitOccured = false;
                //add character to history but split line it it is too long
                if (newChar == '\n')
                {
                    m_History.Add("");
                }
                else if (m_History[m_History.Count - 1].Length >= m_Cols - 1)
                {
                    m_History[m_History.Count - 1] += "\\";
                    m_History.Add(newChar.ToString());
                    splitOccured = true;
                }
                else
                {
                    m_History[m_History.Count - 1] += newChar;
                }

                if (m_History.Count > m_Rows)
                {
                    int rowIdx = 0;
                    //reset gpu data
                    m_HistoryDeviceBuffer.Memset(0);

                    m_History.RemoveAt(0);

                    foreach (string s in m_History)
                    {
                        int colIdx = 0;
                        foreach (char c in s)
                        {
                            m_HistoryDeviceBuffer[m_Cols * rowIdx + colIdx] = (float)(c - ' ');
                            colIdx += 1;
                        }
                        rowIdx += 1;
                    }

                    Clear();

                    for (rowIdx = 0; rowIdx < m_History.Count; ++rowIdx)
                    {
                        MyDrawStringHelper.DrawStringFromGPUMem(m_HistoryDeviceBuffer, 0, rowIdx * (MyDrawStringHelper.CharacterHeight + 1), 0, 0x999999, VBODevicePointer, TextureWidth, TextureHeight, rowIdx * m_Cols, m_Cols);
                    }
                }

                else
                {
                    int    lastRow    = m_History.Count - 1;
                    String lastString = m_History[lastRow];
                    if (lastString.Length > 0)
                    {
                        m_HistoryDeviceBuffer[m_Cols * lastRow + lastString.Length - 1] = (float)(lastString.Last() - ' ');
                    }

                    if (splitOccured)
                    {
                        m_HistoryDeviceBuffer[m_Cols * lastRow - 1] = (float)('\\' - ' ');
                        MyDrawStringHelper.DrawStringFromGPUMem(m_HistoryDeviceBuffer, 0, (lastRow - 1) * (MyDrawStringHelper.CharacterHeight + 1), 0, 0x999999, VBODevicePointer, TextureWidth, TextureHeight, (lastRow - 1) * m_Cols, m_Cols);
                    }
                    MyDrawStringHelper.DrawStringFromGPUMem(m_HistoryDeviceBuffer, 0, lastRow * (MyDrawStringHelper.CharacterHeight + 1), 0, 0x999999, VBODevicePointer, TextureWidth, TextureHeight, lastRow * m_Cols, m_Cols);
                }
            }
        }
コード例 #11
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);
            }
        }