I want to implement a custom loss function (from this paper: https://arxiv.org/abs/1706.00909) in MatConvNet.
My code uses the DagNN wrapper. I want to modify the class SegmentationLoss() to use a custom loss function, custom_loss() instead of vl_nnloss(). For the forward() pass, custom_loss() returns the calculated loss value.
What I don't understand is what custom_loss() should do during the backward() pass in SegmentationLoss(). What is the additional input derOutputs, where does it come from and what should be the return value of custom_loss()?
Thanks!
Related
I estimated parameters of a non- linear arx model with the system identification toolbox in matlab. I was wondering how I can use these results as a function or maybe directly on other inputs. So basically I want to call my arx model function and get the desired output to the given input.
This is the OutputFcn of my estimated model
How would a function of that model look like.
Thank you for your help and pleas keep in mind that I am new to matlab and coding.
Of course I can compare or simulate the model with an iddata object. But thats not useful for my desired application to use the models function with other inputs or to find the deviations to the measured output in dependence to the input.
Best regards
Suppose I want to define a "useful" function that takes a THREE.Vector2 as well as some scaler values as inputs. What's the best syntax for defining the function if I want other people to easily understand the types of the parameters that need to be passed into the function? Sample (that doesn't work):
export function clipToBox(v: THREE.Vector2, boxWidth, boxHeight) {
const clippedVector = new THREE.Vector2
// Do some clever clipping math...
return clippedVector
}
Example of what we want users of our function to see when editing
My use case is this: a function called 'time' that will return how long it takes to run any function you give it.
So the time function needs to know all the parameters to pass into the function when it calls it.
I know how to pass a function into another function, but how can I pass all its parameters, without knowing in advance how many and what type they are, so they can be used when calling the function?
For example, if I pass in an array of all the parameters I need to send, is there some Dart way to call a function by expanding an array into a list of parameters? Or perhaps there's another way to capture and pass a function call, including all parameters, as one executable object?
I'm also interested in knowing if there's a more Dartful way to accomplish what I'm trying to do re: timing function calls.
I believe using a List of parameters with the apply method is the most common way and practical of doing this and I have seen something similar used to pass parameters for JS interop. As far as I know, there isn't a way to expand an array into a list of parameters like you can for javascript. You could of course create your own object to pass arguments, but I think it would add unnecessary complexity and end up being more difficult.
Example of passing parameters to function in dart:js here.
I'm currently trying to create a vectorSUM function in google scripts, which would sum up all vectors. I've looked into using the arguments method, but would much rather prefer using a rest parameter like the built in SUM function uses. I keep getting the error "missing formal parameter" this is my code. How would I go about using Optional parameters, as well as rest parameters in a custom function?
function vectorAdd(vector1, [vector2, ...]) {}
The built in SUM function uses
(value1, [value2, ...])
How can I achieve this?
I've been reading a Concepts of Programming Languages by Robert W. Sebesta and in chapter 9 there is a brief section on passing a SubProgram to a function as a parameter. The section on this is extremely brief, about 1.5 pages, and the only explanation to its application is:
When a subprogram must sample some mathematical function. Such as a Subprogram that does numerical integration by estimating the area under a graph of a function by sampling the function at a number of different points. Such a Subprogram should be usable everywhere.
This is completely off from anything I have ever learned. If I were to approach this problem in my own way I would create a function object and create a function that accomplishes the above and accepts function objects.
I have no clue why this is a design issue for languages because I have no idea where I would ever use this. A quick search hasn't made this any clearer for me.
Apparently you can accomplish this in C and C++ by utilizing pointers. Languages that allow nested Subprograms such as JavaScript allow you do do this in 3 separate ways:
function sub1() {
var x;
function sub2() {
alert( x ); //Creates a dialog box with the value of x
};
function sub3() {
var x;
x = 3;
sub4( sub2 ); //*shallow binding* the environment of the
//call statement that enacts the passed
//subprogram
};
function sub4( subx ) {
var x;
x = 4;
subx();
};
x=1;
sub3();
};
I'd appreciate any insight offered.
Being able to pass "methods" is very useful for a variety of reasons. Among them:
Code which is performing a complicated operation might wish to provide a means of either notifying a user of its progress or allowing the user to cancel it. Having the code for the complicated operation has to do those actions itself will both add complexity to it and also cause ugliness if it's invoked from code which uses a different style of progress bar or "Cancel" button. By contrast, having the caller supply an UpdateStatusAndCheckCancel() method means that the caller can supply a method which will update whatever style of progress bar and cancellation method the caller wants to use.
Being able to store methods within a table can greatly simplify code that needs to export objects to a file and later import them again. Rather than needing to have code say
if (ObjectType == "Square")
AddObject(new Square(ObjectParams));
else if (ObjectType == "Circle")
AddObject(new Circle(ObjectParams));`
etc. for every kind of object
code can say something like
if (ObjectCreators.TryGetValue(ObjectType, out factory))
AddObject(factory(ObjectParams));
to handle all kinds of object whose creation methods have been added to ObjectCreators.
Sometimes it's desirable to be able to handle events that may occur at some unknown time in the future; the author of code which knows when those events occur might have no clue about what things are supposed to happen then. Allowing the person who wants the action to happen to give a method to the code which will know when it happens allows for that code to perform the action at the right time without having to know what it should do.
The first situation represents a special case of callback where the function which is given the method is expected to only use it before it returns. The second situation is an example of what's sometimes referred to as a "factory pattern" or "dependency injection" [though those terms are useful in some broader contexts as well]. The third case is commonly handled using constructs which frameworks refer to as events, or else with an "observer" pattern [the observer asks the observable object to notify it when something happens].