Xcode10 beta6: Argument labels '(frame:)' do not match any available overloads with UIButton - xcode10beta6

Xcode10, beta6, in my project code:
let button = UIButton(frame: CGRect(x: 10,y: 10, width:30, height:30))
then Xcode show me the error:
Argument labels '(frame:)' do not match any available overloads
1. Overloads for 'UIButton' exist with these partially matching parameter lists: (type: UIButtonType), (contentsOfFile: String?), (coder: NSCoder)
Anyone can help? Thanks very much.

Related

Ray[RLlib] Custom Action Distribution (TorchDeterministic)

We know that in the case of a Box (continuous action) Action Space, the corresponding Action Distribution is DiagGaussian (probability distribution).
However, I want to use TorchDeterministic (Action Distribution that returns the input values directly).
This is the code, taken from https://github.com/ray-project/ray/blob/a91ddbdeb98e81741beeeb5c17902cab1e771105/rllib/models/torch/torch_action_dist.py#L372:
class TorchDeterministic(TorchDistributionWrapper):
"""Action distribution that returns the input values directly.
This is similar to DiagGaussian with standard deviation zero (thus only
requiring the "mean" values as NN output).
"""
#override(ActionDistribution)
def deterministic_sample(self) -> TensorType:
return self.inputs
#override(TorchDistributionWrapper)
def sampled_action_logp(self) -> TensorType:
return torch.zeros((self.inputs.size()[0], ), dtype=torch.float32)
#override(TorchDistributionWrapper)
def sample(self) -> TensorType:
return self.deterministic_sample()
#staticmethod
#override(ActionDistribution)
def required_model_output_shape(
action_space: gym.Space,
model_config: ModelConfigDict) -> Union[int, np.ndarray]:
return np.prod(action_space.shape)
With the proper imports, I copied and pasted the contents of this class into a file named custom_action_dist.py.
I imported it with:
from custom_action_dist import TorchDeterministic
registered my custom_action_dist with:
ModelCatalog.register_custom_action_dist("my_custom_action_dist", TorchDeterministic)
and in config I specified:
"custom_action_dist": "my_custom_action_dist"
However, I’m getting the following error:
"File "/home/user/DRL/lib/python3.8/site-packages/ray/rllib/models/torch/torch_action_dist.py", line 38, in logp
return self.dist.log_prob(actions)
AttributeError: 'TorchDeterministic' object has no attribute 'dist'"
It seems that I must specify a probability distribution.
Can somebody help me, tell me which one that is?
Thank you and looking forward for your reply!

How to use the global variable in another function? [duplicate]

Im writing a small code using Memcache Go API to Get data stored in one of its keys . Here are few of lines of code i used ( got the code from Go app-engine docs )
import "appengine/memcache"
item := &memcache.Item {
Key: "lyric",
Value: []byte("Oh, give me a home"),
}
But the line 2 gives me a compilation error "expected declaration, found 'IDENT' item"
I'm new to Go , not able to figure out the problem
The := Short variable declaration can only be used inside functions.
So either put the item variable declaration inside a function like this:
import "appengine/memcache"
func MyFunc() {
item := &memcache.Item {
Key: "lyric",
Value: []byte("Oh, give me a home"),
}
// do something with item
}
Or make it a global variable and use the var keyword:
import "appengine/memcache"
var item = &memcache.Item {
Key: "lyric",
Value: []byte("Oh, give me a home"),
}
I was getting the same error, but the reason was completely different.
I was using following package name.
package go-example
Seems like, it's not a valid package name. After removing the hyphen, it worked.
This error also shows up when assigning value to a variable whose name is a keyword
Like using var:= 2
This also causes the error "expected declaration, found 'IDENT' item"
So correct the name and it will be fine

how do I access a JSON file after it has been decoded

I can't figure out how to access this output from JSON
p (2 items)
0:"message" -> "ok"
1:"results" -> List (1 item)
key:"results"
value:List (1 item)
[0]:Map (4 items)
0:"uid" -> "1"
1:"name" -> "TallyMini"
2:"camera" -> "2"
3:"Version" -> "0.1.0"
enter code here
lst.add(convertDataToJson[1]['value']['name']);
I have tried various combinations of indexs 'result', 'list', 'value', name
I guess you are using http and get a JSON object from the server. And in this case, call json.decode() method then
Flutter understands JSON as a Map . ( Map<String, dynamic> json).
So, to get the value of name field, firstly you need to access to results field.
json['results'] . It is a list, and continue accessing to the name field.
It my answer is not helpful for you, please show me more your code.
You can try like as:
String name= jsonData['results'][0]['name'];
Please let me know it's work or not.

linking jupyter widget text box to a function plotting a graph

I am trying to construct a user interface in Jupyter notebook that is able to link one function with a text widget and button widget.
My function creates a plot for the stock price of a given stock from a start date to end date. The functions is as follow
import pandas_datareader as pdr
from datetime import datetime
def company(ticker):
strt=datetime(2020,1,1)
end=datetime.now()
dat=pdr.get_data_yahoo(ticker, strt, end)
return dat['Close'].plot(grid=True)
The following command plots apple stock price.
company('AAPL')
Now i create a text and button widget as follow
import ipywidgets as ipw
box=ipw.Text(
value='Stock handle',
placeholder='Type something',
description='String:',
disabled=False)
btn=ipw.ToggleButton(
value=False,
description='Plot',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Description',
icon='check' # (FontAwesome names without the `fa-` prefix))
I tried to link the function company with box as follow:
box.on_submit(company)
When I write AAPL in box it gives me error "TypeError: object of type 'Text' has no len()
"
My goal is to create an interface where i write the name of the stock('AAPL') in the box and click the btn at which point the plot of the stock price will appear.
Any help is appreciated. Thank you.
When you attach a function with on_submit, the entire widget gets passed as the argument to the function (not just the text value). So within your company function, ticker is actually your instance of the Text widget. Hence the error, as you cannot call len on a widget.
To get the text value of the widget, use ticker.value, which you should be able to call len on just fine.
def print_it(ticker):
# print(len(ticker)) # raises TypeError, you're calling len on the Text widget
print(len(ticker.value)) # will work, as you're accessing the `value` of the widget which is a string
t = ipywidgets.Text(continuous_update=False)
t.on_submit(print_it)
t
NB. the on_submit method is deprecated as of ipywidgets 7.0, much better to create your box using use box.observe(), and when you create your box include continuous_update=False as a kwarg. With this method, a dictionary of info gets passed to your function, so you need to parse out the new value and print it.
def print_it(ticker):
print(ticker['new']) # will work, as you're accessing the string value of the widget
t = ipywidgets.Text(continuous_update=False)
t.observe(print_it, names='value')
t

Latex or HTML summary output table for vglm regression objects (VGAM)

I'm trying to get a latex or html output of the regression results of a VGAM model (in the example bellow it's a generalized ordinal logit). But the packages I know for this purpose do not work with a vglm object.
Here you can see a little toy example with the error messages I'm getting:
library(VGAM)
n <- 1000
x <- rnorm(n)
y <- ordered( rbinom(n, 3, prob=.5) )
ologit <- vglm(y ~ x,
family = cumulative(parallel = F , reverse = TRUE),
model=T)
library(stargazer)
stargazer(ologit)
Error in objects[[i]]$zelig.call : $ operator not defined for this S4 class
library(texreg)
htmlreg(ologit)
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘extract’ for signature ‘"vglm"’
library(memisc)
mtable(ologit)
Error in UseMethod("getSummary") : no applicable method for 'getSummary' applied to an object of class "c('vglm', 'vlm', 'vlmsmall')"
I just had the same problem. My first work around is to run the OLogit Regression with the polr function of the MASS package. The resulting objects are easily visualizable / summarizable by the usual packages (I recommend sjplot 's tab_model function for the table output!)
2nd Option is to craft your own table, which you then turn into a neat HTML object via stargazer.
For this you need to know that s4 objects are not subsettable in the same manner as conventional objects (http://adv-r.had.co.nz/Subsetting.html). The most straight forward solution is to subset the object, i.e. extract the relevant aspects with an # instead of a $ symbol:
sumobject <- summaryvglm(yourvglmobject)
stargazer(sumpbject#coef3, type="html", out = "RegDoc.doc")
A little cumbersome but it did the trick for me. Hope this helps!