I am using DEAP to resolve a problem using a genetic algorithm. I need to create a custom function to generate the individuals. This function checks the values inside in order to append 0 or 1.
Now I'm trying to register this function on the toolbox.
The function I have written is called individual_creator(n), n=IND_SIZE and it returns a vector [].
After creating individuals as a list:
creator.create("Individual", list, fitness=creator.FitnessMin)
I registered individual and population on my toolbox like the following:
toolbox.register("individual", individual_creator, creator.Individual, n=IND_SIZE)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
Using this code this error appeared: TypeError: individual_creator() got multiple values for argument 'n'
Registering individual without using n parameter doesn't work either:
toolbox.register("individual", individual_creator, creator.Individual)
TypeError: 'type' object cannot be interpreted as an integer
Could someone please help me? I need to create custom individuals using my function and then create the population.
Thank you in advance!
Related
I have an model value, when i do the each iteration it works fine.
<ul>
<li>See here : </li>
{{#each selectedCreditCard.balances.tenures as |balance|}}
<li>Balances is : {{balance}}</li>
{{/each}}
</ul>
But I require to sorted the value by desc way. so I use the computed method to do the desc the array.
sortTenuresBy:['desc'],
sortedTenures: Ember.computed.sort('selectedCreditCard.balances.tenures', 'sortTenuresBy'),
maxTenure:Ember.computed(function(){
return this.get('sortedTenures').get('firstObject');
But getting error as like this:
Assertion Failed: When using #each to observe the array 3,8,12,24, the array must return an object
how to fix this? please help me
If you look at API definition for Ember.computed.sort; it requires a property key (that is selectedCreditCard.balances.tenures in your case) and a sort definition (that is sortTenuresBy in your case). However, if you look at the examples provided; the sort definition must be either a plain property name or a property name followed by sort type such as name:desc or key:asc and so on. In summary; it is not possible to use Ember.computed.sort for plain arrays as in your case. I admit the API documentation is vague.
For your case; you have to either write the computed property as a function; which is what you do not want I suppose; because it is the common way; or you can make use of the following addon. What is great about ember-awesome-macros is you can nest the provided computed macros.
If you look at API for array.sort; it says "combines the functionality of both Array.prototype.sort() and Ember.computed.sort". Hence we can use this one. You want the array to be sorted in descending; I suppose something like the following
sortTenuresBy: array.reverse(array.sort('selectedCreditCard.balances.tenures'))
should work.
Is there is way to access cell that contains my UDF?
I need to reset some cache when function with same parameters is run from different cell.
Didn't find anything suitable in exceldna utils.
Thanks,
Alex
You can call
ExcelReference caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;
The result will be an ExcelReference if you're called from a sheet formula. It might be null if you're called via Application.Run or a few other ways.
ExcelReference is a wrapper for the C API sheet reference.
I am retrieving results using Mongoid, but I want to add a new attribute to each of the records returned in an instance variable using the key. How would I go about doing this?
In PHP I would do this by looping through the array and inserting it based on the key of the object. I am unable to figure out how this can be done in Ruby when I receive the message: Model ABC can't be converted into an Integer.
Update: I ended up adding a method in the model to achieve what I was trying to do.
I'll try to point you in the right direction.
If you have an array of records and what to loop through it, use Array#each: http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-each
You can write attributes easily: http://rdoc.info/github/mongoid/mongoid/Mongoid/Attributes#write_attribute-instance_method
Hope that helps
I want to use addJSONData function for adding a new row to my jqGrid.
$("#grid_id")[0].addJSONData(newRowJSONData);
It works, but when I try
$("#grid_id")[1].addJSONData(newRowJSONData)
this gives an undefined error please help me how can I add more than one new row to jqGrid?
The expression $("#grid_id")[1] means the second element on the page, which has the id equal to grid_id. Because the ids must be unique on the page the expression $("#grid_id")[1] produce undefined result. So $("#grid_id")[1].addJSONData(newRowJSONData) should gives an error.
I don't understand you statement: "I want to use addJSONData function for adding a new row to my jqGrid.". I could understand that you what to fill the grid with data which you have as an object, but I see no sense in the requirement to use an special method. If you need some help you should describe your real problem without the choosing of one special method. Then other people could try to help you.
I have this line of code:
delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic', 'Position', [13 135 98 20], ...
'Callback', 'delete_graphic');
and a little bit upper this function:
function delete_graphic
global rr_list
selected = get(rr_list, 'Value');
selected
return;
why this code is not working? I really dont understand...
What do I need? I create one button and a listbox, clicking on button - deleting selected element from a listbox.
Thx for help.
PS
Always getting this error:
??? Undefined function or variable 'delete_graphic'.
??? Error while evaluating uicontrol Callback
here is all my code: http://paste.ubuntu.com/540094/ (line 185)
The generally-preferred way to define a callback function is to use a function handle instead of a string. When you use a string, the code in the string is evaluated in the base workspace. This means that all the variables and functions used in the string have to exist in the base workspace when the callback is evaluated. This makes for a poor GUI design, since you don't really want the operation of your GUI dependent on the base workspace (which the user can modify easily, thus potentially breaking your GUI).
This also explains the error you are getting. The function delete_graphic is defined as a subfunction in your file rr_intervals.m. Subfunctions can only be called by other functions defined in the same m-file, so delete_graphic is not visible in the base workspace (where your string callback is evaluated). Using a function handle callback is a better alternative. Here's how you would do it:
Change the callback of your button (line 216) from 'delete_graphic' to #delete_graphic.
Change the function definition of delete_graphic (line 185) to:
function delete_graphic(hObject,eventdata)
where hObject is the handle of the object issuing the callback and eventdata is optional data provided when the callback is issued.
EDIT:
If you want to pass other arguments to delete_graphic, you can perform the following steps:
Add the additional input arguments to the end of the function definition. For example:
function delete_graphic(hObject,eventdata,argA,argB)
Use a cell array when you set the callback for your button, where the first cell contains the function handle and the subsequent cells each contain an input argument. For example:
set(delete_btn,'Callback',{#delete_graphic,A,B});
There is one caveat to this, which is that the values A and B stored in the cell array are fixed at what they are when you set the callback. If you change A or B in your code it will not change the values stored in the cell-array callback.
If you aren't able to use the above solution (i.e. if A and B need to change value), there are a few other options for how you can share data among a GUI's callbacks:
You can rework the organization of your code to make use of nested functions. This makes it very easy to share data between callbacks. Some nice examples of using nested functions to create GUIs can be found in the MathWorks File Exchange submission GUI Examples using Nested Functions by Steven Lord.
You can store data in the UserData property of a uicontrol object. To access or update it, you just need the object handle.
You can use the functions SETAPPDATA/GETAPPDATA to attach data to a handle graphics object (i.e. uicontrol).
Since it appears your code was created using GUIDE, you can make use of the handles structure GUIDE creates to store data using the GUIDATA function.