//saves the final result matrix as dataAttributes/dataItems -> SimpleDataModel
    private void EncodeResultToSimpleDataModel()
    {
        for (var i = 1; i <= K; i++)
        {
            for (var j = 1; j <= _input.Count; j++)
            {
                if (_clusterMatrix[i, j] != Vector3.zero)
                {
                    var dataItem = new DataItem();

                    var x        = new DataAttribute();
                    var y        = new DataAttribute();
                    var z        = new DataAttribute();
                    var centroid = new DataAttribute();

                    var valueX        = _clusterMatrix[i, j].x;
                    var valueY        = _clusterMatrix[i, j].y;
                    var valueZ        = _clusterMatrix[i, j].z;
                    var valueCentroid = (float)i;

                    x.Init(j, "x", valueX + "", DataAttribute.Valuetype.ValFloat);
                    y.Init(j, "y", valueY + "", DataAttribute.Valuetype.ValFloat);
                    z.Init(j, "z", valueZ + "", DataAttribute.Valuetype.ValFloat);
                    centroid.Init(0, "centroid", valueCentroid + "", DataAttribute.Valuetype.ValFloat);

                    dataItem.Add(x);
                    dataItem.Add(y);
                    dataItem.Add(z);
                    dataItem.Add(centroid);

                    _simpleDataModel.Add(dataItem);
                }
            }
        }
    }
 public void addFloatMatrixColwise(float[][] data)
 {
     for (int i = 0; i < data.Length; i++)
     {
         var dataItem = new DataItem();
         for (int j = 0; j < data[0].Length; j++)
         {
             var dataAttribute = new DataAttribute();
             dataAttribute.Init(j, "var" + j, data[i][j] + "", DataAttribute.Valuetype.ValFloat);
             dataItem.Add(dataAttribute);
         }
         Add(dataItem);
     }
 }
        private GenericDatamodel ReadCsv()
        {
            GenericDatamodel dataModel = new SimpleDatamodel();

            var pathToData = _path + _filename;

            if (File.Exists(pathToData))
            {
                var fileContent = System.IO.File.ReadAllLines(pathToData);

                if (fileContent.Length == 0)
                {
                    throw new FileLoadException("Empty file!");
                }

                var start           = 0;
                var attributeTitles = TrimStringArray(fileContent[0].Split(_delimiter.ToCharArray()));
                if (!_hasHeader)
                {
                    for (var i = 0; i < attributeTitles.Length; i++)
                    {
                        attributeTitles[i] = "Column_" + (i + 1);
                    }
                }
                else
                {
                    start++;
                }

                var datatypes = new DataAttribute.Valuetype[attributeTitles.Length];
                var firstRow  = TrimStringArray(fileContent[start].Split(_delimiter.ToCharArray()));
                for (var i = 0; i < firstRow.Length; i++)
                {
                    datatypes[i] = DataAttribute.GetDataType(firstRow[i]);
                }

                for (var i = start; i < fileContent.Length; i++)
                {
                    var dataItem   = new DataItem();
                    var attributes = TrimStringArray(fileContent[i].Split(_delimiter.ToCharArray()));
                    if (attributes.Length != attributeTitles.Length)
                    {
                        throw new FileLoadException("Can not load " + pathToData + ". Row " + i + " does not contain the same amount of columns than the first row(" + attributeTitles.Length + ").");
                    }
                    ;

                    for (var j = 0; j < attributes.Length; j++)
                    {
                        var dataAttribute = new DataAttribute();
                        dataAttribute.Init(j, attributeTitles[j], attributes[j], datatypes[j]);
                        dataItem.Add(dataAttribute);
                    }
                    dataModel.Add(dataItem);
                }

                if ((_hasHeader && fileContent.Length - 1 != dataModel.GetDataItems().Count) || (!_hasHeader && fileContent.Length != dataModel.GetDataItems().Count))
                {
                    throw new FileLoadException("Incomplete Parsing! Not all rows were transformed imported as data items!");
                }
                ;

                return(dataModel);
            }
            else
            {
                throw new FileLoadException("Did not find file '" + pathToData + "'.");
            }
        }