In the space param, I declare it as:
"langevin": hp.choice("langevin", [True, False])
The fmin successfully ran. However when I use: model = Regressor(**best), it throws: CatBoostError: catboost/private/libs/options/json_helper.h:157: Can't parse parameter "langevin" with value: 1
How can I force the return value as True?
Related
I'm looking for a way to retrive index value via metatable. This is my attempt:
local mt = { __index =
{
index = function(t, value)
local value = 0
for k, entry in ipairs(t) do
if (entry == value) then
value = k
end
end
return value
end
}
}
t = {
"foo", "bar"
}
setmetatable(t,mt)
print(t.index(t,"foo"))
Result is 0 instead of 1. Where I'm wrong?
My attempt:
local mt = {
__index = function(t,value)
for index, val in pairs(t) do
if value == val then
return index
end
end
end
}
t = {
"foo",
"bar",
"aaa",
"bbb",
"aaa"
}
setmetatable(t,mt)
print(t["aaa"]) -- 3
print(t["asd"]) -- nil
print(t["bbb"]) -- 4
print(t["aaa"]) -- 3
print(t["bar"]) -- 2
print(t["foo"]) -- 1
Result is 0 instead of 1. Where [am I] wrong?
The code for the index function is wrong; the problem is not related to the (correct) metatable usage. You're shadowing the parameter value when you declare local value = 0. Subsequent entry == value comparisons yield false as the strings don't equal 0. Rename either the parameter or the local variable:
index = function(t, value)
local res = 0
for k, entry in ipairs(t) do
if entry == value then
res = k
end
end
return res
end
An early return instead of using a local variable in the first place works as well and helps improve performance.
To prevent such errors from happening again, consider getting a linter like Luacheck, which will warn you if you shadow variables. Some editors support Luacheck out of the box; otherwise there are usually decent plugins available.
I'm making a chat program using a flat buffer.
I want to move four ball variables.
ex) value1 = true, value2 = false, value3 = true, value = false,
The schema name of Flatbuffers is ServerInfo.
(i = 0; i < 3; i++)
ServerInfo.AddValue(fb, value [i]);
I wrote this code.
A total of four values should be added, but only one was added.
The result I want) true, false, true, false.
Actual Results ) true, true, true, true
The ServerInfo value.value portion of the test [i] was the same as the value [0].
How can we put it together once?
Definition of ServerInfo.AddValue.
public static space addValue (FlatBufferBufferBufferBufferBufferBuilder) {builder.AddBool(4, Value, false); }
You are setting the same scalar field 4 times. Not sure what language you're doing this in, but that should result in an assert. If you want to store 4 values, replace bool in your schema with [bool].
I am guessing you're coming from Protobuf and expecting each field to be repeated?
export const getValueFromPsetProperty = (pset: string, property: string) => R.pipe(
R.prop('pSets'),
R.find(R.propEq('name', pset)),
R.propOr([], 'properties'),
R.find(R.propEq('name', property)),
R.propOr(null, 'value'),
R.ifElse(isValueValid, null,R.identity),
);
The last pipe does not work. What I want to do is to pass the value if isValueValid is true. How should I do this?
It doesn't look like you're using R.ifElse correctly. All first three arguments should be functions:
A predicate function
The function to execute if the predicate is true
The function to execute if the predicate is false
So from what you're describing, you want to return the value unchanged if isValueValid returns true. In this case your R.ifElse should be:
R.ifElse(isValueValid, R.identity, someOtherFunction)
You may want to consider R.unless which will run a function only if a predicate is false. If value is valid, then the R.unless returns it unchanged.
R.unless(isValueValid, someFunctionIfValueIsNotValid);
I have a pretty mind-bending setup right now. I have a regular function that returns a table with functions in it under keys "string" and "number":
function defGeneric()
local function funcNumber(a)
return 2*a^2
end
local function funcString(a)
return a.." - test"
end
local returnTable={}
returnTable["number"]=funcNumber
returnTable["string"]=funcString
return returnTable
end
And that works fine. But what I want to do now is make the table that this function returns callable. To illustrate, let's say we have v=defGeneric(). Specifically:
If v is called with a string str, return the result of v["string"](str)
If v is called with a number n, return the result of v["number"](n)
This is obviously a job for metatables, so I can (in my function) add the code to set a metatable:
local metaTable = {
__call = function (...) -- "call" event handler
return
end
}
setmetatable(returnTable,metaTable)
But I don't know what I would put after that return statement. I don't think I can reference returnTable, because this table will be called like so:
v=defGeneric()
v("test")
And I need to reference v's "string" function (there certainly could be multiple defGeneric() tables in one program).
I think the answer here might be some self trick but I can't wrap my head around how. How do I reference a metatable's table from the metatable?
The first argument passed to the __call function is the table it is being called on, the table returned from the function in this case. You can use type(a) to get the type of the argument as a string, so you could do something like this:
function defGeneric()
local result = {
['number'] = function(a) return 2*a^2 end,
['string'] = function(a) return a.." - test" end
}
setmetatable(result, {
__call = function(t,a)
local f = t[type(a)]
if f == nil then return "No handler for type "..type(a) end
-- alternate:
-- if f == nil and t['string'] ~= nil then return t['string'](tostring(a)) end
return f(a)
end
})
return result
end
local def = defGeneric()
print("string: "..tostring(def('sample string')))
print("number: "..tostring(def(5)))
print("table: "..tostring(def({})))
print("boolean: "..tostring(def(1 > 5)))
output
string: sample string - test
number: 50.0
table: No handler for type table
boolean: No handler for type boolean
alternate output
string: sample string - test
number: 50.0
table: table: 0x18537e0 - test
boolean: false - test
playerOneScore is a int, How can I pass it to use a label to display the score? This code just prints %i...
-(void)updateScoreLabels{
playerOneScoreLabel.text = #"%i",playerOneScore;
playerTwoScoreLabel.text = #"%i",playerTwoScore;
playerThreeScoreLabel.text = #"%i",playerThreeScore;
playerFourScoreLabel.text = #"%i",playerFourScore;
}
You need to initialize string using convenience constructor:
playerOneScoreLabel.text = [NSString stringWithFormat:#"%i",playerOneScore];
...
What you actually have in your code is comma operator - it evaluates its 1st parameter (that is assigns #"%i" string to a label), then evaluates and returns 2nd parameter - playerOneScore.