Does resampling have to be instantiated in mlr3? - instantiation

It was said that resampling object should be instantiated before training in mlr3 book. But sometimes it was not and can be trained and predicted successfully. I want to know when it should be instantiated with $instantiate(task) slot.

If you pass an resampling object that is not instantiated, it will be instantiated internally by some/most methods.
In general, instantiate it.

Related

Referenced Model Block with varying inport dimensions

I am having some severe trouble ith Simulink right now. I basically use parameterized Referenced Models for easy reusing of Model Blocks inside a larger model. However I have run into a problem:
Model Arguments can't be used on non-tunable parameters (like inport dimensions)
Variable-Sizdes signals cannot simply be created by MUXing signals together. (So using variable-sized inports is also difficult.)
The required dimensional information sadly gets lost at the model boundary.
A few pictures to showcase my problem:
it is easy enough to define the port dimensions inside this model. But I want this model to be reusable various dimensionalities (Maybe I want to Mux together 3 instead of 2 signals).
The math inside should be fine with any dimension and in a subsystem this should work just fine, but the model boundary makes it hard for me to create this in an easy to re-use way...
Any tips would be appreciated.

Is there a way to pass an object instance from MATLAB to Simulink?

I have created a class 'BinaryTree' in Matlab. I would like to pass an instance of this object to Simulink, and use the associated class methods in Simulink. For example, I would like to pass a function in the format of 'Binarytree' class to Simulink and iteratively evaluate this function using 'ComputeTree', which is a method defined in the 'BinaryTree' class, using the simulation values.
I have considered using Matlab System Objects. I was wondering if there are better-suited ways to meet my objective, or if there are any available examples using Matlab System Objects to do what is described above.
Why not just use the Matlab Function block from the library
You don't need to pass anything, you can use persistent memory if you need to keep track of previous values.

How to create an Estimator that trains new samples after already fitted to initial dataset?

I'm trying to create my own Estimator following this example I found in the Spark source code DeveloperApiExample.scala.
But in this example, everytime I call fit() method in Estimator, it will return a new Model.
I want something like fitting again to train more samples that was not trained yet.
I thought in creating a new method in the Model class to do so. But I'm not sure if it makes sense.
It's maybe good to know that my model don't need to process all dataset again to train a new sample and we don't want to change the model structure.
The base class for a spark ml Estimator is defined here. As you can see, the class method fit is a vanilla call to train the model using the input data.
You should reference something like the LogisticRegression class, specifically the trainOnRows function where the input is an RDD and optionally an initial coefficient matrix (output of a trained model). This will allow you to iteratively train a model on different data sets.
For what you need to achieve, please remember that your algorithm of choice must be able to support iterative updates. For example, glm's, neural networks, tree ensembles etc.
If you know how to improve the training in your model without retraining with the already used data, you can't do it in the same class, because you want a Model that is also a Estimator, but sadly this is not possible directly because both are abstract classes, and can't be used mixed in the same class.
As you say, you can provide in the model a method that will return the Estimator to improve/increase the training.
class MyEstimator extends Estimator[MyModel] {
...
}
class MyModel extends Model[MyModel] {
def retrain: MyEstimator = // Create a instance of my estimator that it carries all the previous knowledge
}
You can use PipelineModels to save and load and continue fitting models:
MLlib standardizes APIs for machine learning algorithms to make it easier to combine multiple algorithms into a single pipeline, or workflow. This section covers the key concepts introduced by the Pipelines API, where the pipeline concept is mostly inspired by the scikit-learn project.
Find exemplary code here.

How to add a custom layer and loss function into a pretrained CNN model by matconvnet?

I'm new to matconvnet. Recently, I'd like to try a new loss function instead of the existing one in pretrained model, e.g., vgg-16, which usually uses softmax loss layer. What's more, I want to use a new feature extractor layer, instead of pooling layer or max layer. I know there are 2 CNN wrappers in matconvnet, simpleNN and DagNN respectively, since I'm using vgg-16,a linear model which has a linear sequence of building blocks. So, in simpleNN wrapper, how to create a custom layer in detail, espectially the procedure and the relevant concept, e.g., do I need to remove layers behind the new feature extractor layer or just leave them ? And I know how to compute the derivative of the loss function so the details of computation inside the layer is not that important in this question, I just want to know the procedure represented by codes. Could someone help me? I'll appreciate it a lot !
You can remove the older error or objective layer
net.layer('abc')=[];
and you can add new error code in vl_nnloss() file

Neural Network bias

I'm building a feed forward neural network, and I'm trying to decide how to implement the bias. I'm not sure about two things:
1) Is there any downside to implementing the bias as a trait of the node as opposed to a dummy input+weight?
2) If I implement it as a dummy input, would it be input just in the first layer (from the input to the hidden layer), or would I need a dummy input in every layer?
Thanks!
P.S. I'm currently using 2d arrays to represent weights between layers. Any ideas for other implementation structures? This isn't my main question, just looking for food for thought.
Implementation doesn't matter as long as the behaviour is right.
Yes, it is needed in every layer.
2d array is a way to go.
I'd suggest to include bias as another neuron with constant input 1. This will make it easier to implement - you don't need a special variable for it or anything like that.