I'm trying to use sagetex package, but then I found this kind of problem when running the code
the result
Here is the code I tried to run:
\documentclass{article}
\usepackage{sagetex}
\usepackage{graphicx}
\usepackage{fancyvrb}
\begin{document}
Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
$\sage{number_of_partitions(1269)}$ integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.
Here's some Sage code:
\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}
The second derivative of $f$ is
\[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
\]
Here's a plot of $f$ from $-1$ to $1$:
\sageplot{plot(f, -1, 1)}
\sageplot[scale=.5]{plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1))}
we know that 2010 factors to $\sage{factor(2010)}$
\begin{sagesilent}
m=identity_matrix(QQ,3)
m[0]=m[0]+m[1]
m[1]=m[1]-m[2]
m[2]=m[2]-2*m[1]
m[1]=m[1]+3*m[0]
m[0]=2*m[0]
\end{sagesilent}
Compute the rref of $\sage{m}$
\begin{sageblock}
g(x)=taylor(tan(x),x,0,10)
\end{sageblock}
$$\tan(x)=\sage{g(x)}$$
\end{document}
When I try to compile this, I get:
**** Error in Sage code on line 23 of file.tex! Traceback follows.
Traceback (most recent call last):
File "file.sagetex.sage.py", line 39, in <module>
_st_.plot(_sage_const_1 , format='notprovided', _p_=plot3d(sin(pi*(x**_sage_const_2 +y**_sage_const_2 ))/_sage_const_2 ,(x,-_sage_const_1 ,_sage_const_1 ),(y,-_sage_const_1 ,_sage_const_1 )))
NameError: name 'y' is not defined
Once a single error occurs, the rest of the Sage output may be lost, leading to all of the question marks. The problem is this line:
\sageplot[scale=.5]{plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1))}
and in particular, you have not defined y. (In SageMath, x is automatically defined to be a variable, but not y.) If you add this before the plot, it should work:
\begin{sagesilent}
var('y')
\end{sagesilent}
Related
I'm trying to use the groebner function in Sympy to solve a system of multivariate polynomials in GF(9) = GF(3)[g]/(g**2 + 1). When I do this I get the error
File
"/Applications/Spyder.app/Contents/Resources/lib/python3.9/sympy/polys/groebnertools.py",
line 37, in groebner
orig, ring = ring, ring.clone(domain=domain.get_field())
File
"/Applications/Spyder.app/Contents/Resources/lib/python3.9/sympy/polys/domains/domain.py",
line 846, in get_field
raise DomainError('there is no field associated with %s' % self)
DomainError: there is no field associated with GF(3)[g]/(g**2 + 1)
I reduced the code to the minimum that gives this get_field() failure. I also looked at is_field ... which was True!?
I know that GF and similar mechanisms fail for non-prime finite fields, but I thought that all would be well, if I defined my own GF(9) using a finite extension.
Am I missing something, or does get_field() not realize that gf9 is a field?
My minimal code
from sympy import Symbol, Poly
from sympy.polys.agca.extensions import FiniteExtension
g = Symbol('g')
gf9 = FiniteExtension(Poly(g**2 + 1, g, modulus=3)) # correct GF(9)
print('gf9 = ', gf9, 'type =', type(gf9), 'is_field?', gf9.is_Field)
print()
print('field associated with', gf9, '=', gf9.get_field())
Response
gf9 = GF(3)[g]/(g**2 + 1) is_field? True
Traceback (most recent call last):
File
"/Applications/Spyder.app/Contents/Resources/lib/python3.9/spyder_kernels/py3compat.py",
line 356, in compat_exec
exec(code, globals, locals)
File "/Users/rick/.spyder-py3/temp.py", line 17, in
print('field associated with', gf9, '=', gf9.get_field())
File
"/Applications/Spyder.app/Contents/Resources/lib/python3.9/sympy/polys/domains/domain.py",
line 846, in get_field
raise DomainError('there is no field associated with %s' % self)
DomainError: there is no field associated with GF(3)[g]/(g**2 + 1)
Any help appreciated :)
Addendum: I just noticed that I never asked my real question: How can I use Sympy's groebner function with GF(3)[g]/(g**2 + 1)?
A program to run a Schmid-Leiman transformation using SPSS's Matrix language was published in 2005 by Woolf & Preising in Behavior Research Methods volume 37, pages 48 to 58). It is probably not important for you to know what a Schmid-Leiman transformation is, but I'll explain in comments if you feel it is necessary.
In modifying the program for my own data, I'm getting an error I can't figure out:
Error # 12302 in column 12. Text: ,
Syntax error.
Execution of this command stops.
Error in RIGHT HAND SIDE of COMPUTE command.
The MATRIX statement skipped.
Here is the beginning of the code. The error is showing as coming in Line 6:
* Encoding: UTF-8.
* Schmid-Leiman Solution for 2 level higher-order Factor analysis.
Matrix.
* ENTER YOUR SPECIFICATIONS HERE.
* Enter first-order pattern matrix.
Compute F1={.461, .253, -.058, -.069;
.241, .600, .143, .033;
.582, .047, -.077, -.125;
.327, .297, -.120, -.166;
.176, .448, -.240, -.099;
.680, .069, -.036, -.138;
.415, .228, -.091, -.153;
.
.
.
.390, .205, .002, -.098;
.164, .369, -.170, -.047
}.
As shown above, the text generating the error is shown as a comma (,), but the actual text (following the COMPUTE statement) in column 12 is an open bracket ({). So I have no idea what is going on. Can someone help?
For reference, the original code as proposed by Woolf & Preising (2005) is found here;
The Woolf & Preising article is found here
PS: The sample program given in the link above does run on my copy of SPSS. Here's the beginning of that code:
* Schmid-Leiman Solution for 2 level higher-order Factor analysis.
Matrix.
* ENTER YOUR SPECIFICATIONS HERE.
* Enter first-order pattern matrix.
Compute F1={0.099, 0.5647, -0.1521;
0.0124, 0.9419, -0.1535;
-0.1501, 0.6177, 0.4218;
0.7441, -0.0882, 0.1425;
0.6241, 0.2793, -0.1137;
0.8693, -0.0331, 0.0289;
-0.0154, -0.2706, 0.6262;
-0.0914, 0.0995, 0.7216;
0.1502, 0.0835, 0.398}.
Documentation is not helpful to me at all.
First, I tried using set() ,but I don't understand what it means by
set an instance for future calls
I could successfully feed my data using my dataset's structure described below.
So, I am not sure why I need to use set for that as it mentioned.
Here is my feature sequence of type scipy.sparse after I called nonzero() method.
[['66=1', '240=1', '286=1', '347=10', '348=1'],...]
where ... imply, same structure as previous elements
Second problem I encountered is Tagger.probability() and Tagger.marginal().
For Tagger.probability, I used the same input as Tagget.tag(), and I get this follwoing error.
and if my input is just a list instead of list of list. I get the following error.
Traceback (most recent call last):
File "cliner", line 60, in <module>
main()
File "cliner", line 49, in main
train.main()
File "C:\Users\Anak\PycharmProjects\CliNER\code\train.py", line 157, in main
train(training_list, args.model, args.format, args.use_lstm, logfile=args.log, val=val_list, test=test_list)
File "C:\Users\Anak\PycharmProjects\CliNER\code\train.py", line 189, in train
model.train(train_docs, val=val_docs, test=test_docs)
File "C:\Users\Anak\PycharmProjects\CliNER\code\model.py", line 200, in train
test_sents=test_sents, test_labels=test_labels)
File "C:\Users\Anak\PycharmProjects\CliNER\code\model.py", line 231, in train_fit
dev_split=dev_split )
File "C:\Users\Anak\PycharmProjects\CliNER\code\model.py", line 653, in generic_train
test_X=test_X, test_Y=test_Y)
File "C:\Users\Anak\PycharmProjects\CliNER\code\machine_learning\crf.py", line 220, in train
train_pred = predict(model, X) # ANAK
File "C:\Users\Anak\PycharmProjects\CliNER\code\machine_learning\crf.py", line 291, in predict
print(tagger.probability(xseq[0]))
File "pycrfsuite/_pycrfsuite.pyx", line 650, in pycrfsuite._pycrfsuite.Tagger.probability
ValueError: The numbers of items and labels differ: |x| = 12, |y| = 73
For Tagger.marginal(), I can only produce error similar to first error shown of Tagger.probabilit().
Any clue on how to use these 3 methods?? Please give me shorts example of use cases of these 3 methods.
I feel like there must be some example of these 3 methods, but I couldn't find one. Am I looking at the right place. This is the website I am reading documentation from
Additional info: I am using CliNER. in case any of you are familiar with it.
https://python-crfsuite.readthedocs.io/en/latest/pycrfsuite.html
I know this questions is over a year old, but I just had to figure out the same thing as well -- I am also leveraging some of the CliNER framework. For the CliNER specific solution, I forked the repo and rewrote the predict method in the ./code/machine_learning/crf.py file
To obtain the marginal probability, you need to add the following line to the for loop that iterates over the pycrf_instances after yseq is created (see line 196 here)
y_probs = [tagger.marginal(y, ii) for ii, y in enumerate(yseq)]
And then you can return that list of marginal probabilities from the predict method -- you will in turn be required to rewrite additional functions in the to accommodate this change.
Im trying to use the Tikz externalize, because for some tikz pictures the file gets to big and exceeds the memory size. I found a lot of other topics with similar problems, but non of the solutions worked for me or I did not implement them well enough.
I'm using Winedt 10.2(also tried Winedt 9)
Mixtex 2.9
The structure of the report:
Final_Report.tex
--Layout.tex
--Simulation_model.tex
----plot_baseunit.tex(Tikz picture)
Final_Report.tex
\documentclass[10pt,a4paper]{report}
\input{./Lay_out/layout.tex}`
\begin{document}
\input{./Chapters/Simulation_Model/Simulation_Model.tex}
\end{document}
layout.tex
\usepackage{tikz,pgfplots}
\usetikzlibrary{arrows,decorations.pathmorphing,shadows,fit,positioning,shapes,chains, plotmarks,automata,positioning}
\usepackage{subcaption}
%\usepackage[pdftex]{graphicx}
\usetikzlibrary{external,calc,patterns,angles,quotes,shapes.geometric,positioning}
\pgfplotsset{plot coordinates/math parser=false}
\tikzexternalize[prefix=figures/,shell escape=-enable-write18]
\newlength\figureheight
\newlength\figurewidth
%Standard figure dimension
\newcommand{\plotx}{12.0cm}
\newcommand{\ploty}{6.0cm}
\newcommand{\plotysub}{3.0cm} %y-dimension of seperate subplots
%Subplot dimensions (2 plots wide subplots)
\newcommand{\subtwoplotx}{5.25cm}
\newcommand{\subtwoploty}{4.5cm}
\tikzstyle{block} = [draw, rectangle, node distance=2.0cm, minimum height=3em, minimum width=4em]
\tikzstyle{sum} = [draw, circle, node distance=2.0cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
Simulation_model.tex
\begin{figure}[H]
\resizebox{\textwidth}{!}{%
\input{./figures/plot_baseunit.tex}
}%
\caption{The throughput and cycle time of the production line plotted against the process time of a base unit workstation, as bottleneck of the system. The horizontal dotted lines represent the designed throughput and cycle time of the Honda/JLR(green) and Audi/Porsche roof systems(purple).}
\label{fig:Base_unit_through}
\end{figure}
When I try to run this using PDFTeXify it gives the following error.
(figures/plot_baseunit.tex
===== 'mode=convert with system call': Invoking 'pdflatex -halt-on-error -interaction=batchmode -jobname
"figures/Final_Report-figure0" "\def\tikzexternalrealjob{Final_Report}\input{Final_Report}"' ========
! Package tikz Error: Sorry, the system call 'pdflatex -halt-on-error-interact
ion=batchmode -jobname "figures/Final_Report-figure0" "\def\tikzexternalrealjob
{Final_Report}\input{Final_Report}"
did NOT result in a usable output file
'figures/Final_Report-figure0' (expected one of .pdf:.jpg:.jpeg:.png:).
Please verify that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'.
Sometimes it is also named 'write 18' or something like that. Or maybe the command simply failed?
Error messages can be found in 'figures/Final_Report-figure0.log'. If you continue now, I'll try to typeset the picture.
If I just press enter the right figures come out, but this does not work for large files and then the memory size is exceeded.
Thanks in advance!.
The same question as Building Lates/Tex arguments in lua with a more complex case :
Part II
A more adequate model :
I try to replace the plot arguments by a lua production:
Original:
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[smooth,samples=100,domain=-3.0:2.0] plot(\x,{(\x-1.0)^2.0*(\x+3.0)});
\end{tikzpicture}%
Replacement by a "manual" macro : works fine
\def\tempD{(\x-1)*(\x-1)*(\x+3)}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[smooth,samples=100,domain=-3.0:2.0] plot(\x,{\tempD}); % works fine
\end{tikzpicture}%
Trials to use a string produced by lua to replace the manual macro : still to be found
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
%\draw[smooth,samples=100,domain=-3.0:2.0] plot(\x,{\strfunc??????}); % the correct \strfuncXX is still to be found !
\end{tikzpicture}%
Trials to find the correct \strfuncXX, taking account egreg's infos :
\def\strfuncA{\luaexec{tex.write("(\\x-1)*(\\x-1)*(\\x+3)")}} % fails in draw, probably because it is not expanded enough as an argument of draw
%\edef\strfuncAA{\luaexec{tex.write("(\\x-1)*(\\x-1)*(\\x+3)")}} % fails because \luaexec non expandable
\def\strfuncB{\directlua{tex.write("(\\x-1)*(\\x-1)*(\\x+3)")}} % fails because \directlua has a problem managing the "\\"
\def\strfuncC{\directlua{tex.write("(x-1)*(x-1)*(x+3)")}}
\edef\strfuncCC{\directlua{tex.write("(x-1)*(x-1)*(x+3)")}} % works fine ... except that we get an expression with xs instead of \xs
\def\strfuncD{\directlua{tex.write("(\string\ x-1)*(\string\ x-1)*(\string\ x+3)")}} % \strfuncD fails (why ?)
%\edef\strfuncDD{\directlua{tex.write("(\string\ x-1)*(\string\ x-1)*(\string\ x+3)")}} % \strfuncD fails so \edef will fail
Moving from \luaexec to \luadirect (or \directlua) created a problem with the compulsory \x I have to produce that I cannot solve.