0

I have a class library with objects using Math.net. The library contains classes that contain data and methods. As a trial I am instantiating an object of a member class and then call the the load method to fill the object with data from a file. However, the data loaded does not get passed to the new object. When I dump the object to the screen I get:

EchoStateNet.EchoState+Input

Where I should get a data dump. Below the library with the class definition and a test calling it.

namespace EchoStateNet
{
    public class EchoState
    {
        // class that holds network input data
        public class Input
        {
            public Matrix<double> dataSet { get; set; }     // matrix holding train / test / run input data           

            public Input() : base() { }     // default constructor

            // method to load network data
            public void load(string filePath, string fileName)
            {
                try
                {
                    dataSet = DelimitedReader.Read<double>(Path.Combine(filePath, fileName), false, ",", false);   // read the input data
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error loading data. Exception: " + ex);
                }
            }           

        }

And the part that calls this:

namespace TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            EchoState.Input data = new EchoState.Input();

            data.load("..\\..", "MackeyGlass_t17.txt");

            Console.WriteLine("Input data:");
            Console.WriteLine(data.ToString());
        }
    }
}

The output I am getting suggests to me that I may not have instantiated an object properly, but the syntax of Math.net is a bit different than a typical List<> declaration, so I'm not sure what's wrong.

jdelange
  • 763
  • 2
  • 10
  • 22

1 Answers1

0

What do you expect this to output?:

data.ToString()

Your Input class never overrides the .ToString() method, so the default implementation from System.Object is to output the class name. Which is this:

EchoStateNet.EchoState+Input

If you want to output something else, override the .ToString() method in your class. Something like this:

public override string ToString()
{
    // return some string representation here
}

As for what a valid string representation of your object should be, that's up to you. The only state your object holds is a Matrix<double>. I'm not familiar with that type, so I don't know what one might expect it to look like. But whatever you want it to look like, you'd format that in the ToString() method (using things like StringBuilder and/or string.Format() and return the resulting string.

David
  • 208,112
  • 36
  • 198
  • 279
  • this helps, so it's not the instantiation. The `ToString()` is implemented in the Math.net library for the `Matrix<>` class. So what I understand from this is that this implementation may not be accessible in this way. – jdelange Nov 15 '15 at 17:26
  • @jdelange: If `Matrix` has a `ToString()` already then all you'd need to do in your method is: `return dataSet.ToString();` – David Nov 15 '15 at 17:28
  • Excellent! This indeed outputs the contents of `dataSet`. So now I can add other data types and methods in the same manner. – jdelange Nov 15 '15 at 17:32