so i want to make encoding using spread spectrum with audio. i was try using this web to do it, the website try to encoding with image. the string was input must be convert to binary. but i change input string to use bytes (the result from encrypt using AES). i was using python and the result from print bi it's none, why is it none?
here's the code i tried:
password = b'\xbb\xbaS`'
def password(password):
print(password)
g = password
le=len(g)
i=0
a=list()
for i in range(le):
a.append(0) #initializing
j=0
for i in g:
a[j]=i
j+=1
print(a) #ascii values
bi= [ [ 0 for i in range(8) ] for j in range(le) ]
j=0
i=7
while(j<le):
while(i>-1):
bi[j][i]=a[j]%2
a[j]=(a[j]-bi[j][i])//2
i-=1
j+=1
i=7
print(bi)#binary
i=0
j=0
while(j<le):
while(i<8):
if bi[j][i]==0:
bi[j][i]=-1
i+=1
j+=1
i=0
i=0
j=0
print(bi)#this is where 0s are converted to -1s
and here's the terminal result:
[0]
[0, 0]
[0, 0, 0]
[0, 0, 0, 0]
[187, 186, 83, 96]
[[1, 0, 1, 1, 1, 0, 1, 1], [1, 0, 1, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0, 1, 1], [0, 1, 1, 0, 0, 0, 0, 0]]
[[1, -1, 1, 1, 1, -1, 1, 1], [1, -1, 1, 1, 1, -1, 1, -1], [-1, 1, -1, 1, -1, -1, 1, 1], [-1, 1, 1, -1, -1, -1, -1, -1]]
None
I have a question about using plot and disk together in one manipulate function in mathematica.
I have this piece of code right now:
Plot[h[t], {t, 0, ttot}, PlotRange -> {0, 30}]
Manipulate[
Plot[
h0 + v0*t - 1/2*g*(t)^2, {t, 0, 10},
PlotRange -> {{-1, 8}, {0, 11.5}}
],
{t, 0, ttot, 0.001}, {m, 0.001, 0.1, 0.001, ImageSize -> Tiny}, {v0,
0, 5, 0.01, ImageSize -> Tiny}, {h0, 0, 10, 0.01, ImageSize -> Tiny}
]
What I want to do is display a disk inside the plot representing a flying object (its position is on the curve, according to actual time and height). How do I do it?
You should show the definitions of the symbols you use : h[t], v0, ttot etc.
My understanding of what you are after :
trajectory[p0_, v0_, a_, t_] = p0 + v0 t - 1/2 a t^2;
x0 = 3;
v0y = 1;
g = 9.81;
ttot = 3;
Manipulate[ParametricPlot[trajectory[{x0, h0}, {v0x, v0y}, {0, g}, t], {t, 0, ttot}, Epilog -> {Disk[trajectory[{x0, h0}, {v0x, v0y}, {0, g}, tcurrent], 0.5]}, PlotRange -> All], {v0x, 0, 5, 0.01}, {h0, 0, 10, 0.01}, {tcurrent, 0, ttot, 0.01}]
I am trying to upgrade some equations that currently are written against Mathematica 5 to get them to work in Mathematica 7.
F = Graphics[
ContourPlot[
x^2 + (2)*y^2 + (-1)*((1)/(3))*x, {x, -1, 1}, {y, -1, 1},
ContourShading -> False, ContourStyle -> {RGBColor[1, 0, 1]},
Contours -> 20, PlotPoints -> 100]];
G = ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2*Pi},
PlotStyle -> {RGBColor[0, 174/255, 239/255]}];
H = DeleteCases[F, {x_, y_} /; (x^2 + y^2 > 1), 5];
Show[{H, G}, AspectRatio -> Automatic, Frame -> False, Axes -> True,
AxesOrigin -> {0, 0}, AxesLabel -> {x, y}, Ticks -> None]
It should look like this:
, but id does look like this:
and it gives the following error:
Thread::tdlen: Objects of unequal length in
{{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}+{{},<<21>>,{}}
cannot be combined. >>
and if you hover over the image you get the following in a tooltip:
The specified setting for the option GraphicsBoxOptions, PlotRange cannot be used.
Coordinate index X is out of range for the enclosing GraphicsComplex
there are a lot of those Coordinate ones all with different coordinates.
And the second one I'm having difficulty with is:
P1 = {{(5)/10*Cos[u]*Cos[v], (5)/10*Sin[u]*Cos[v], (5)/10*Sin[v]}, {u,
0, 2*Pi}, {v, -Pi/2, Pi/2}};
P2 = {{(5)/10*Cos[u], 0, (5)/10*Sin[u]}, {u, 0, 2*Pi}};
P3 = {{(5)/10*Cos[u], (5)/10*Sin[u], 0}, {u, 0, 2*Pi}};
P4 = {{0, (5)/10*Cos[u], (5)/10*Sin[u]}, {u, 0, 2*Pi}};
U = {P1, P2, P3, P4};
XL = {{-1, 1}, {-1, 1}, {-1, 1}};
XV = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
XS = {"x", "y", "z"};
f[a_, b_, c_] := {a, 1.1*b[[2]]*c};
g[a_, b_] := {(b*# &) /# a};
T = Text ### MapThread[f, {XS, XL, XV}];
A = Line ### MapThread[g, {XL, XV}];
F = (ParametricPlot3D[Evaluate[Evaluate ## #]][[1]] &) /# U;
OPT = {Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1}, PlotRange -> XL,
ViewPoint -> {2.4, 1.3, 2},
DisplayFunction ->
Identity};
L = {LightSources -> {{{0.1, 0, 1}, RGBColor[0.68, 0.88, 0.96]}}};
gr1 = (Show[Graphics3D[#], OPT, L] &) /# {{EdgeForm[], F}, {Dashing[{0.03, 0.03}],
GrayLevel[0.7], A}, {T}};
gr2 = DeleteCases[Graphics[Show[Graphics3D[{A, EdgeForm[], F}], OPT,
RenderAll -> False]], {__, _Polygon}, 3];
Show[{gr1, gr2}, AspectRatio -> Automatic]
This one should look like: , but does look like:
which and it gives these errors:
ParametricPlot3D::write: Tag Plus in x^2+y^2 is Protected. >>
Graphics3D::optx : Unknown option RenderAll
Graphics3D::optx : Unknown option LightSources
If I then remove the Unknown options, those errors disappear but it still looks wrong:
Also, if you hover over the last image in mathematica you get the following message repeated several times in a tooltip
Times is not a Graphics3D primitive or directive
Second one, great circles partly hidden, axes partly dashed:
r = 1.01/2; d = 1/(100 r);
v1 = Riffle[
Table[r { Cos[\[Phi]], Sin[\[Phi]], -d}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}],
Table[r { Cos[\[Phi]], Sin[\[Phi]], d}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}]];
v2 = Riffle[
Table[-r { Cos[\[Phi]], -d, Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}],
Table[-r { Cos[\[Phi]], d, Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}]];
v3 = Riffle[
Table[r { -d, Cos[\[Phi]], Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}],
Table[r { d, Cos[\[Phi]], Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}]];
lx = {{{1, 0, 0}, {2, 0, 0}}}/2;
ly = {{{0, 1, 0}, {0, 2, 0}}}/2;
lz = {{{0, 0, 1}, {0, 0, 2}}}/2;
A2 = Line ### {lx, ly, lz, -lx, -ly, -lz};
Graphics3D[
{
FaceForm[None, Black], EdgeForm[],
GraphicsComplex[#,
Table[Polygon[Mod[{i, i + 1, i + 3, i + 2}, Length[v], 1]], {i,
1, Length[v] - 1, 2}]] & /# {v1, v2, v3}, {Opacity[0.75],
RGBColor[0.68`, 0.88`, 0.96`], Sphere[{0, 0, 0}, 1/2]},
{Dashing[{0.02, 0.02}], Black, A}, T, A2
},
Boxed -> False,
Lighting -> {{"Directional", RGBColor[0.68`, 0.88`, 0.96`],
ImageScaled#{0.1, 0, 1}}}, BoxRatios -> {1, 1, 1},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
BaseStyle -> FontSize -> 14, ViewPoint -> {2.4`, 1.3`, 2},
ViewVertical -> {0, 0, 1}
]
It is a little hard to tell from the picture what you want for the second graphic. Please try this and tell me what is right and what is lacking.
P1 = {{(5)/10*Cos[u]*Cos[v], (5)/10*Sin[u]*Cos[v], (5)/10*Sin[v]}, {u,
0, 2*Pi}, {v, -Pi/2, Pi/2}};
P2 = {{(5)/10*Cos[u], 0, (5)/10*Sin[u]}, {u, 0, 2*Pi}};
P3 = {{(5)/10*Cos[u], (5)/10*Sin[u], 0}, {u, 0, 2*Pi}};
P4 = {{0, (5)/10*Cos[u], (5)/10*Sin[u]}, {u, 0, 2*Pi}};
U = {P1, P2, P3, P4};
XL = {{-1, 1}, {-1, 1}, {-1, 1}};
XV = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
XS = {"x", "y", "z"};
f[a_, b_, c_] := {a, 1.1*b[[2]]*c};
g[a_, b_] := {(b*# &) /# a};
T = Text ### MapThread[f, {XS, XL, XV}];
A = Line ### MapThread[g, {XL, XV}];
F = ParametricPlot3D[##, Mesh -> False][[1]] & ### U;
OPT = {Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1},
PlotRange -> XL, ViewPoint -> {2.4, 1.3, 2}};
L = Lighting -> {{"Directional",
RGBColor[0.68, 0.88, 0.96], {{5, 5, 4}, {5, 5, 0}}}};
gr1 = Graphics3D[#, OPT, L] & /# {{Opacity[0.5], F},
{Dashing[{0.03, 0.03}], GrayLevel[0.7], A},
{T}};
Show[gr1]
Here is another take that may be closer to the original. You lose the v7 ability to rotate the graphic with this.
gr1 = Rasterize[Graphics3D[#, OPT, L],
Background -> None] & /# {F, {Dashing[{0.03, 0.03}],
GrayLevel[0.7], A}, T};
Show[gr1]
First one:
ContourPlot[x^2 + (2)*y^2 + (-1)*((1)/(3))*x, {x, -1, 1}, {y, -1, 1},
ContourShading -> False, ContourStyle -> {RGBColor[1, 0, 1]},
Contours -> 20, RegionFunction -> (#1^2 + #2^2 <= 1 &),
BoundaryStyle -> Blue]
[Edit]
Second one, using the given values for A and T:
Show[
ParametricPlot3D[{(5)/10*Cos[u]*Cos[v], (5)/10*Sin[u]*Cos[v], (5)/10*
Sin[v]}, {u, 0, 2*Pi}, {v, -Pi/2, Pi/2},
MeshFunctions -> {#1 &, #2 &, #3 &}, PlotStyle -> Opacity[0.75],
Mesh -> {{0}, {0}, {0}}, MeshStyle -> Black, BoundaryStyle -> Black,
Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
ViewPoint -> {2.4`, 1.3`, 2},
Lighting -> {{"Directional", RGBColor[0.68`, 0.88`, 0.96`],
ImageScaled#{0.1, 0, 1}}}],
Graphics3D[{{Dashing[{0.03, 0.03}], Black, A}, {T}}]
]
I think the axes will need to be done as separate interior/exterior segments.
The great circles show through in this version; preventing that will require drawn partial curves instead of mesh lines, if that's required.
Using kernlab I've trained a model with code like the following:
my.model <- ksvm(result ~ f1+f2+f3, data=gold, kernel="vanilladot")
Since it's a linear model, I prefer at run-time to compute the scores as a simple weighted sum of the feature values rather than using the full SVM machinery. How can I convert the model to something like this (some made-up weights here):
> c(.bias=-2.7, f1=0.35, f2=-0.24, f3=2.31)
.bias f1 f2 f3
-2.70 0.35 -0.24 2.31
where .bias is the bias term and the rest are feature weights?
EDIT:
Here's some example data.
gold <- structure(list(result = c(-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), f1 = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1), f2 = c(13.4138113499447,
13.2216999857095, 12.964145772169, 13.1975227965938, 13.1031520152764,
13.59351759447, 13.1031520152764, 13.2700658838026, 12.964145772169,
13.1975227965938, 12.964145772169, 13.59351759447, 13.59351759447,
13.0897162110721, 13.364151238365, 12.9483051847806, 12.964145772169,
12.964145772169, 12.964145772169, 12.9483051847806, 13.0937231331592,
13.5362700880482, 13.3654209223623, 13.4356400945176, 13.59351759447,
13.2659406408724, 13.4228886221088, 13.5103065354936, 13.5642812689161,
13.3224757352068, 13.1779418771704, 13.5601730479315, 13.5457299603578,
13.3729010596517, 13.4823595997866, 13.0965264603473, 13.2710281801434,
13.4489887206797, 13.5132372154748, 13.5196188787197), f3 = c(0,
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0)), .Names = c("result",
"f1", "f2", "f3"), class = "data.frame", row.names = c(NA, 40L
))
To get the bias, just evaluate the model with a feature vector of all zeros. To get the coefficient of the first feature, evaluate the model with a feature vector with a "1" in the first position, and zeros everywhere else - and then subtract the bias, which you already know. I'm afraid I don't know R syntax, but conceptually you want something like this:
bias = my.model.eval([0, 0, 0])
f1 = my.model.eval([1, 0, 0]) - bias
f2 = my.model.eval([0, 1, 0]) - bias
f3 = my.model.eval([0, 0, 1]) - bias
To test that you did it correctly, you can try something like this:
assert(bias + f1 + f2 + f3 == my.model.eval([1, 1, 1]))
If I'm not mistaken, I think you're asking how to extract the W vector of the SVM, where W is defined as:
W = \sum_i y_i * \alpha_i * example_i
Ugh: don't know best way to write equations here, but this just is the sum of the weight * support vectors. After you calculate the W, you can extract the "weight" for the feature you want.
Assuming this is correct, you'd:
Get the indices of your data that are the support vectors
Get their weights (alphas)
Calculate W
kernlab stores the support vector indices and their values in a list (so it works on multiclass problems, too), anyway any use of list manipulation is just to get at the real data (you'll see that the length of the lists returned by alpha and alphaindex are just 1 if you just have a 2-class problem, which I'm assuming you do).
my.model <- ksvm(result ~ f1+f2+f3, data=gold, kernel="vanilladot", type="C-svc")
alpha.idxs <- alphaindex(my.model)[[1]] # Indices of SVs in original data
alphas <- alpha(my.model)[[1]]
y.sv <- gold$result[alpha.idxs]
# for unscaled data
sv.matrix <- as.matrix(gold[alpha.idxs, c('f1', 'f2', 'f3')])
weight.vector <- (y.sv * alphas) %*% sv.matrix
bias <- b(my.model)
kernlab actually scales your data first before doing its thing. You can get the (scaled) weights like so (where, I guess, the bias should be 0(?))
weight.vector <- (y.sv * alphas) %*% xmatrix(my.model)[[1]]
If I understood your question, this should get you what you're after.