I'am a beginner in s.m.l programming and am trying to solve very simle problem in emacs(Ubuntu) that is written below
val x = 4
val y = 3
val z = x * y
I use above code and it showing this following error :
"[use failed: Io: openIn failed on "f.sml", No such file or Directory]
uncaught exceptional error
raised at: ../compiler/TopLevel/interact/interact.sml:24.14-24.28 "
so where did I do wrong ? please Help me. I know its a very simple Problem but am just a beginner.
Thank you :)
Related
I've installed all the requirements and successful in running the local server but when I tried to run the prediction part of this 4th_umpire(The cricket match predictor using Random Forest algo project I'm getting the following error:-
Here I'm presenting the error part of the code as mentioned in the error image.
def _transform(self, X, handle_unknown='error'):
X_list, n_samples, n_features = self._check_X(X)
X_int = np.zeros((n_samples, n_features), dtype=np.int)
X_mask = np.ones((n_samples, n_features), dtype=np.bool)
if n_features != len(self.categories_):
raise ValueError(
"The number of features in X is different to the number of "
"features of the fitted data. The fitted data had {} features "
"and the X has {} features."
.format(len(self.categories_,), n_features)
)
The exception line is if n_features != len(self.categories_): although I've checked that OneHotEncoder part and it seems ok to me.
I'm trying to use the line magic %lprun in jupyter notebook running a python 2.7.5 kernel.
The code I'm trying to run is the following:
%load_ext line_profiler
distance = 20
veg_slope = 0
slope = 10
%lprun test = bal.run('forest', veg_slope, slope, distance, FFDI=100)
The bal.run code is a bit complicated, but executing the code with those parameters will output the following tuple:
(35.02405579440225, 'BAL-40')
However if I try to use the %lprun magic I get the following error:
File "<string>", line 1
test = bal.run(\'forest\', veg_slope, slope, distance, FFDI=100)
^
SyntaxError: unexpected character after line continuation character
Not sure what is happening there, but as a test I tried to run a simple python function like print together with the line_profiler, and that worked.
Anyone has any idea of what the problem could be?
I have just had the same issue in Jupyter / Python 3.6 using example code from a presentation available here.
I'm still a newbie but the traceback ends with the same syntax error:
File "", line 1
df[\'high_rate_normalized\'] = normalize(df, df[\'high_rate\'])
^
SyntaxError: unexpected character after line continuation character
Change to double quotes "
%lprun test = bal.run("forest", veg_slope, slope, distance, FFDI=100)
I have the following constraint in a simple MINLP model:
model.cm2=Constraint(expr = model.xB2 == log(1.0+model.xA2))
This works when I call bonmin (windows64 binary distribution from AMPL)
When swithing to the couenne solver I need to convert to log10 base
model.cm2=Constraint(expr = model.xB2 == 2.3*log10(1.0+model.xA2))
otherwise I get the error:
ApplicationError: Solver (asl) did not exit normally.
model.pprint() gives in the first case:
cm2 : Size=1, Index=None, Active=True
Key : Lower : Body : Upper : Active
None : 0.0 : xB2 - log( 1.0 + xA2 ) : 0.0 : True
I use the anaconda python installation and work with spyder.
Do anyone have an idea of the reason for this behaviour?
I have read the comment from jsiirola, but I do not think that the problem is evaluating the log of a negative number. Here is a complete test problem, that behaves the same way. If I solve with bonmin i can use log() if I use cuonne I have to use ln(10)*log10().
from pyomo.environ import *
solverpathb="..\\solversAMPL\\bonmin\\bonmin"
solverpathc="..\\solversAMPL\\couenne\\couenne"
model=ConcreteModel()
model.x = Var(within=NonNegativeReals,bounds=(1,2),doc='Nonnegative')
model.y = Var(within=NonNegativeReals,doc='Nonnegative')
model.obj = Objective(expr= model.x+model.y, sense=maximize)
model.c1=Constraint(expr = model.y == log(1.0+model.x))
#model.c2=Constraint(expr = model.y == 2.3*log10(1.0+model.x))
#Works with version c1 and c2 of the constraint
#solver = pyomo.opt.SolverFactory("bonmin", executable=solverpathb)
#only constraint c2 works with this solver
solver = pyomo.opt.SolverFactory("couenne", executable=solverpathc)
results = solver.solve(model, tee = True)
model.display()
The log file that should include errors only includes the model. This is the last part of the errors.
...
File "C:/../testproblem.py", line 24, in
results = solver.solve(model, tee = True)
File "C:\Users..\Python\Python36\site-packages\pyomo\opt\base\solvers.py", line 623, in solve
"Solver (%s) did not exit normally" % self.name)
ApplicationError: Solver (asl) did not exit normally.
Note: I can use the following code for the object function, also with couenne
model.obj = Objective(expr= model.x+log(1.0+model.x), sense=maximize)
First, the entire model would be most useful when debugging problems like this. Second, what error is being thrown by Couenne when it exits abnormally?
As to answers:
Pyomo uses the same interface for BONMIN and Couenne (they are both through the ASL), so you should never have to change your expression just because you switched solvers. log and log10 are not the same function, of course, so you are not solving the same problem.
I suspect the problem is that model.xA2 is going less than or equal to -1 (i.e., the solver is asking the ASL to evaluate log(0). The way to verify this is by looking at the solver log. Additionally, you will want to make sure that Pyomo sends "symbolic" labels to the solver so that the error will reference actual variable / constraint names and not just "x1, x2, x3, ..." and "c1, c2, c3, ..." in the error message.
Couenne is a global solver, whereas BONMIN is a local solver. As this is a nonconvex problem, Couenne is probably exploring parts of the solution space that BONMIN never went to.
Using a binary distribution from COIN-OR solved the problem, it was not a pyomo problem. The binary distribution of couenne downloaded from ampl.com doesn't, for some odd reason, accept the log-function, only log10.
I tried the demo app, it works fine but when I tried to integrate my own .jsgf grammar file it is giving error when I tried same thing using .lm file for the same dictionary it is working fine .
I referred to PocketSphinx android demo runtime exception link but it didn't help me out
Following is the code snippet:
private void setupRecognizer(File assetsDir) throws IOException {
// The recognizer can be configured to perform multiple searches
// of different kind and switch between them
File modelsDir = new File(assetsDir, "models");
mRecognizer = defaultSetup()
.setAcousticModel(new File(assetsDir, "en-us-ptm"))
.setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
.setRawLogDir(assetsDir)
.setKeywordThreshold(1e-10f)
.setFloat("-beam", 1e-30f)
.setBoolean("-allphone_ci", true)
.getRecognizer();
mRecognizer.addListener(this);
File languageModel = new File(assetsDir, "commands_gram.gram");
mRecognizer.addGrammarSearch(COMMANDS, languageModel);
}
Following is the error
E/cmusphinx: ERROR: "fsg_search.c", line 141: The word 'next' is missing in the dictionary
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: Decoder_setJsgfFile returned -1
at edu.cmu.pocketsphinx.PocketSphinxJNI.Decoder_setJsgfFile(Native Method)
at edu.cmu.pocketsphinx.Decoder.setJsgfFile(Decoder.java:139)
at edu.cmu.pocketsphinx.SpeechRecognizer.addGrammarSearch(SpeechRecognizer.java:234)
at com.package.ui.SphinxSpeechRecognizerActivity.setupRecognizer(SphinxSpeechRecognizerActivity.java:284)
at com.package.ui.SphinxSpeechRecognizerActivity.access$400(SphinxSpeechRecognizerActivity.java:29)
at com.package.ui.SphinxSpeechRecognizerActivity$3.doInBackground(SphinxSpeechRecognizerActivity.java:239)
at com.package.ui.SphinxSpeechRecognizerActivity$3.doInBackground(SphinxSpeechRecognizerActivity.java:233)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Also I realized that any .jsgf grammar file I am using it is not detecting the last word from the dictionary. before it was working fine after I changed to my own .jsgf grammar file it is giving exception
This line:
E/cmusphinx: ERROR: "fsg_search.c", line 141: The word 'next' is missing in the dictionary
tells you need to add the word 'next' to the dictionary. You used this word in your JSGF grammar, but it was missing in the dictionary. Words are case-sensitive, so you need to make sure you use proper case.
I maybe know your problem.
Your have to make the grammar in correct form,like your space and tab.
I suggest you checking your grammar for block or tab.
Sorry my poor English.
I am trying to implement a hash function and here is my code:
import BitVector
import glob
path = '/home/vguda/Desktop/.txt'
files=glob.glob(path)
hash = BitVector.BitVector(size = 32)
hash.reset(0)
i = 0
for file in files:
bv = BitVector.BitVector( filename = file )
while 1 :
bv1 = bv.read_bits_from_file(8)
if str(bv1) == "":
break
hash[0:8] = bv1 ^ hash[0:8]
hash >> 8
i = i+1
hash_str = ""
hash_str = str( hash )
text_file = open("/home/vguda/Desktop/result.txt ","w")
text_file.write("Hash Code is %s" %hash_str)
text_file.close()
print hash
print (i)
The displayed error is:
"bash: syntax error near unexpected token `('
First, perhaps this happened in copy and paste, but your indenting in your loop is all messed up, I'm not sure which blocks go where.
When you run things in the shell, you need to either tell python to run it:
python myscript.py
Or, put the following line as the first thing in your program to tell bash to run it as a python program:
#!/usr/bin/python
Currently, bash is trying to run your python program as a bash script, and obviously running into syntax errors.