caporaso-lab / sourcetracker2

SourceTracker2
BSD 3-Clause "New" or "Revised" License
61 stars 45 forks source link

Using leave-one-out with positional arguments #86

Open lkursell opened 7 years ago

lkursell commented 7 years ago

In the gibbs argument:

gibbs(sources, sinks=None, alpha1=.001, alpha2=.1, beta=10, restarts=10,
          draws_per_restart=1, burnin=100, delay=1, cluster=None, create_feature_tables=True)

Code If a user defined the parameters outside of the gibbs() call, and then passed in sinks=None, they could get a positional argument, which can be confusing. Using the leave-one-out function therefore requires the user to use **kwargs or specify the parameters within the function.

wdwvt1 commented 7 years ago

I dont understand this issue - the SyntaxError is an expected part of python. If you specify positional arguments after a keyword argument you get errors. The solution to the 'defined parameters outside' is to remove the keyword sinks. For example:

alpha1 = .1
alpha2 = .1
beta = 10
burnins = 100
delay = 1
restarts = 1
draws_per_restart = 1
cluster = c
create_feature_tables = True

# This will fail because a keyword argument occurs before a positional argument.
gibbs(sources, sinks=None, alpha1, alpha2, beta, restart,
          draws_per_restart, burnin, delay, cluster, create_feature_tables)

# This would not fail because no keyword argument precedes a positional argument.
sinks = None
gibbs(sources, sinks, alpha1, alpha2, beta, restart,
          draws_per_restart, burnin, delay, cluster, create_feature_tables)
# or, if you like
gibbs(sources, None, alpha1, alpha2, beta, restart,
          draws_per_restart, burnin, delay, cluster, create_feature_tables)

As I sent to @nscott1 offline.

def f(a,b,c,d,e):
   return a+b+c+d+e

# won't work because we are specifying at least one positional argument after 
# the keyword args
e = 5
f(a=1, b=2, c=3, d=4, e)

a = 1
e = 5
f(a, b=2, c=3, d=4, e)

# will work because the last positional argument occurs before a keyword argument
a = 1
b = 2
f(a, b, c=3, d=4, e=5)
wdwvt1 commented 7 years ago

Sorry, didn't mean to close. I see the offending line here.