Initialize weka Instance with default values - initialization

Is it possible to create a weka Instance object containing all default values (e.g., all 0s)?
By instantiating it as follows:
Instance newInstance = new Instance(dimension);
I just obtain a vector having non-specified values.
Thank you in advance.

There is no default parameter to do it. Apart from looping through attributes and initializing with setValue, a good alternative could be to create a template instance with all default values and use the shallow copy method ( .copy() ) for each new instance (Instance implements Copyable).

Related

MVVM-Light SimpleIoc: Can't create multiple instances dynamically

I am building an WPF application using the MVVM Light Toolkit and specifically SimpleIoc.
I have a parent viewmodel that dynamically creates child viewmodels. When doing this I am using "standard" dependency injection to pass a IConfigService as a parameter to the constructor. I want the IConfigService to be a unique instance for each child viewmodel. So I try this:
IConfigService service = SimpleIoc.Default.GetInstance<IConfigService>(key);
ChildViewModel vm = new ChildViewModel(service);
Where key is a unique identifier for each child viewmodel. According to the documentation of MVVM Light and SimpleIoc this GetInstance method:
...provides a way to get an instance of a given type corresponding to a given key. If no instance had been instantiated with this key before, a new instance will be created.
There is also a remark that the class must have been registered before, else it returns null. In my case it has been, in ViewModelLocator:
var configService = new ConfigService();
SimpleIoc.Default.Register<IConfigService>(() => configService);
However, the GetInstance call returns the same instance every time.
What am I doing wrong here?
You registered an already instantiated object.
SimpleIoc does not create its own instances with this overload. It always returns configService. Either you need to perform the instantiation within the lambda, because you are using a factory overload, or you can do this more easily by just passing the ConfigService type. SimpleIoc will take care of the instantiation itself.

Qt Proxy with type of source object

I have class, say MyClass, inherited from QSqlRelationalTableModel and I need to transpose it (change rows with columns).
This solution was found.
Is it possible to get transposed object of type MyClass after using the proxy? If not, are there any other ways to do it?
Thank you!
EDIT
I wanna use is like this:
MyClass* myObject = new MyClass(this, db);
TransposeProxyModel* trans = new TransposeProxyModel(this);
trans->setSourceModel(myObject);
ui->tableViewDb->setModel(trans);
ui->tableViewDb->setItemDelegate(new QSqlRelationalDelegate(ui->tableViewDb));
It is necessary to paste object of MyClass (or QSqlRelationalTableModel) into QSqlRelationalDelegate.
(edited as per question clarification)
Why do you need to pass the source model into the QSqlRelationalDelegate? If you use the stock delegate then the delegate needs to operate on top of data that it visualizes (data from TransposeProxyModel).
If you have a custom subclass of QSqlRelationalDelegate and you want to access the source data from there for any reason, then you can pass myObject as a second argument to delegate constructor, or you can access it through QModelIndex::model() methods of the index passed to delegate's methods.

Create an array in windows workflow foundation

Is it possible to create a new array in windows workflow? More specifically, in the designer.
I've created a variable of System.Int32[], but when I use it I get a NullReferenceException.
I've tried New Int32(5), and various permutations of Dim - nothing I have tried has worked.
I was able to create the array and pass it as an in/out parameter - this works, however the workflow will need to determine the actual size of the array.
To create and instantiate an array, you have to set a default value to your variable with New Int32(FOO SIZE){} or use an Assign activity to instantiate it with the correct size in runtime
You can also use List(Of T) or any other .NET collection structure to achieve dynamic size.
Note that the value must be the right part of a set expression. So, you can google how to do it in VB.NET and you will be fine.
I assume that if you are creating the array in the designer, as you stated, it is either a workflow variable or a workflow argument. The "WF" way to do this would be to use the "Default Value" column under the "Variables" and/or "Arguments" tab.
If it is an argument then the Default Value column only works if the Direction is "In". If your argument is a property, or an Out, or In/Out direction then you would have to use the method mentioned by Davi.
If you are creating it under the "Variables" tag then using the Default value column would be the more built-in approach. The syntax in the default column would be the same syntax mentioned by Davi: New Int32(FOO SIZE) {}

Dynamic variable for custom component functions in Flex 4

I define a variable which is dynamicaly changes based on the user interactions, for example ID of an object sets to variable when user touches on it. After the ID sets I call a function in a custom component which is related to that object. Like this;
activeObject.videoPlay(event) ---> if the activeObject is video1 ---> video1.videoPlay(event) function will be called.
I tried several variable types when defining the variable activeObject, such as String , Array but didnt work out. By the way the data set to variable is String. When I use String type it gives this error;
Error #1061: Call to a possibly undefined method videoPlay through a reference with static type String.
Is there any way to use a string as a dynamic variable?
Is there any way to use a string as a dynamic variable?
Bracket notation -- obj["dynamicPropertyName"] as Type or in your case (activeObject['videoPlay'] as Function).apply(abc, [event]); You'll obviously want null object checks etc.

Instantiate Local Variable By Value?

I sort of understand why this is happening, but not entirely. I have a base class with a Shared (Static) variable, declared like so:
Public Shared myVar As New MyObject(arg1, arg2)
In a method of a derived class, I set a local variable like so:
Dim myLocalVar As MyObject = myVar
Now when I do something like myLocalVar.Property1 += value, the value in Property1 persists to the next call of that method! I suppose I get why it would be happening; myVar is being set by reference instead of by value, but I've never encountered anything like this before. Is there any way (other than my workaround which is to just create a new object using the property values of myVar) to create myLocalVar by value?
When you create myLocalVar you are creating a new reference to the same shared object. If you truly want a local copy of the shared instance you will need to create a true copy.
This is done by either cloning the instance or with a copy constructor on the type that allows you to create a copy of the instance. This is not as simple as it sounds, however, due to the differences between deep and shallow copying and a cloned or copied instance could create similar problems for you if the property you are accessing is simply a shallow-copied reference to the same instance that the property on the original instance is referencing.
The best thing I to do in this case is to create a local copy of only the parts of the shared instance that you need, rather than copying the entire object graph. This means create a local copy of whatever type Property1 is and using that.

Resources