text:
# 2nd PUC Maths Model Question Paper 4 with Answers

Students can Download 2nd PUC Maths Model Question Paper 4 with Answers, Karnataka 2nd PUC Maths Model Question Papers with Answers helps you to revise the complete Karnataka State Board Syllabus and score more marks in your examinations.

## Karnataka 2nd PUC Maths Model Question Paper 4 with Answers

Time: 3 Hrs 15 Min
Max. Marks: 100

Part-A

Answer all the questions: (10 × 1 = 10)

Question 1.
Let * be a operation defined on the set of rational numbers by a* b = $$\frac{\mathrm{ab}}{4}$$ find the identify element.
a*e = e*a=a

e = 4

Question 2.
Write the values of x for which 2 tan-1 x = cos-1$$\frac{1-x^{2}}{1+x^{2}}$$ holds
x ≥ 1

Question 3.
Construct a 2 × 2 matrix A = [aij] whose elements are given by $$\frac{1}{2}|-3 i+j|$$
A = $$\left[ \begin{matrix} 1 & 1/2 \\ 5/2 & 2 \end{matrix} \right]$$

Question 4.
Find the values of x for which $$\left| \begin{matrix} 3 & x \\ x & 1 \end{matrix} \right|$$ = $$\left| \begin{matrix} 3 & 2 \\ 4 & 1 \end{matrix} \right|$$

x2 = 8
x = ± $$\sqrt{8}$$ = ± 2$$\sqrt{2}$$

Question 5.
Find $$\frac{d y}{d x}$$, if y = sin (x2 + 5)
$$\frac{d y}{d x}$$ = cos(x2 + 5).2x

Question 6.
Evaluate : $$\int e^{x}\left(\frac{x-1}{x^{2}}\right) d x$$
$$=\int e^{x}\left(\frac{1}{x}-\frac{1}{x^{2}}\right) \cdot d x=e^{x}\left(\frac{1}{x}\right)+c$$

Question 7.
Define negative of a vector.
Negative vector is a vector whose magnitude is same with opposite direction

Question 8.
Write the direction cosines of x – axis.
1, 0, 0

Question 9.
Define feasible region in LPP.
The common region determined by all the constraints including non-negative constraints.

Question 10.
If P(A) = $$\frac { 3 }{ 5 }$$, P(B) = $$\frac { 1 }{ 5 }$$
find p(A ∩ B) if A and B are independent events
p(A ∩ B) = p(A), p(B)
p(A ∩ B) = $$3 / 5 \cdot 1 / 5$$ = $$\frac { 3 }{ 25 }$$

Part-B

Answer any ten questions: (10 × 2 = 20)

Question 11.
Show that if f: A → B and g: B → C are one – one, then gof : A → C is also one – one
gof (x1) = gof(x2)
g[f(x1)]=g[(x2)]
f(x1) = f(x2)
x1 = x2
since g and f is one – one, gof is one – one

Question 12.
Show that
sin-1 $$(2 x \sqrt{1-x^{2}})$$ = 2sin-1 x for $$\frac{-1}{\sqrt{2}} \leq x \leq \frac{1}{\sqrt{2}}$$
Let x = sin θ ⇒ θ = sin-1 x
2x $$\sqrt{1-x^{2}}$$ = 2 sin θ $$\sqrt{1-\sin ^{2}} \theta$$
2 sin θ. cos θ = sin 2θ
⇒ sin-1 (2x$$\sqrt{1-x^{2}}$$)
= sin-1(sin 2θ) = 2 sin-1 x

Question 13.
Show that
2 tan-1 $$\frac { 1 }{ 2 }$$ + tan-1 $$\frac { 1 }{ 7 }$$ = tan-1 $$\frac { 31 }{ 17 }$$

Question 14.
If the area of the triangle with vertices (-2,0),(0,4) and (0,k) is 4 square units, find the values of k using determinants.

±4 = $$\frac { 1 }{ 2 }$$ {-2 (4 – k) + (0) }
±4 = K – 4
+4 = k – 4 -4 = k – 4
k = 4 + 4 k = 0
k = 8

Question 15.
Differentiate $$\left(x+\frac{1}{x}\right)^{x}$$ with respect to x,

Question 16.
Find the slope of the tangent to the curve y = $$\frac{\mathbf{x}-1}{\mathbf{x}-2}$$ x ≠ 2 at x = 0

Question 17.
Find $$\frac{d y}{d x}$$, if x2 + xy + y2 = 100
2x + x$$\frac{d y}{d x}$$ + y + 2y $$\frac{d y}{d x}$$ = 0
(x + 2y)$$\frac{d y}{d x}$$ = -(2x + y)
$$\frac{d y}{d x}=\frac{-(2 x+y)}{x+2 y}$$

Question 18.
Evaluate :$$\int \frac{\cos 2 x-\cos 2 \alpha}{\cos x-\cos \alpha} d x$$
$$=\int \frac{\left(2 \cos ^{2} x-1\right)-\left(2 \cos ^{2} \alpha-1\right)}{\cos x-\cos \alpha}, d x$$
$$=\int 2 \frac{(\cos x-\cos \alpha)(\cos x+\cos \alpha)}{\cos x-\cos \alpha}, d x$$
$$=2 \int \cos x+\cos \alpha, d x$$
= 2 sin x + 2x cos α + c

Question 19.
Evaluate $$\int \frac{d x}{x-\sqrt{x}}$$

Question 20.
Find the order and degree, if defined of the differential equation
$$\left(\frac{\mathbf{d}^{2} \mathbf{y}}{\mathbf{d x}^{2}}\right)^{3}+\left(\frac{\mathbf{d y}}{\mathbf{d x}}\right)^{2}+\sin \frac{\mathbf{d y}}{\mathrm{dx}}+1=\mathbf{0}$$
order is 2
degree is not defined

Question 21.
Find $$|\overrightarrow{\mathrm{b}}|$$, if $$(\vec{a}+\vec{b}) \cdot(\vec{a}-\vec{b})=8$$ and $$|\overrightarrow{\mathrm{a}}|$$ = 8$$|\overrightarrow{\mathrm{b}}|$$

Question 22.
Find the area of the parallelogram whose adjacent sides are determined by the vectors $$|\overrightarrow{\mathrm{a}}|$$ = î – ĵ + 3k̂ and $$|\overrightarrow{\mathrm{b}}|$$ = 2î – 7ĵ + k̂

Question 23.
Find the angle between the pair of lines given by
$$|\overrightarrow{\mathrm{r}}|$$ = 3î + 2ĵ – 4k̂ + λ(î + 2ĵ + 2k̂) and $$|\overrightarrow{\mathrm{r}}|$$ = 5î – 2ĵ + µ(3î + 2ĵ + 6k̂)

Question 24.
Let X denote the number of hours you study during a randomly selected school day. The probability that X can take the values of x, has the following form, where k is some constant

find the value of k.
ΣP(x) = 1

k = $$\frac { 1 }{ 5 }$$

Part-C

Answer any ten questions: (10 × 3 = 30)

Question 25.
Determine whether the relation R in the set A = {l,2,3, ……… 13,14} defined as R = {(x,y) : 3x = y = o}, is reflexive, symmetric arid transitive.
y = 3x
R – {(1,3) (2,6) (3, 9) (4,12)}
R is not reflexive as (l,l) ∉ R
R is not symmetric as
(1,3) ∈ R but (3,1) ∉ R
R is not transitive as
(1,3) ∈ R, (3,9) ∈R but (l,9)∉ R

Question 26.
If tan-1 $$\frac{x-1}{x-2}$$ + tan-1 $$\frac{x+1}{x+2}$$ = $$\frac{\pi}{4}$$ , then find the values of x.

Question 27.
If A and B are invertible matrices of the same order, then prove that (AB)-1 = B-1 A-1.
From definition of inverse of matrix
(AB) (AB)-1 =1
A-1 (AB)(AB)-1 = A-1l
(A-1A) B(AB)-1=A-1.
IB (AB)-1 = A-1
B(AB)-1 = A-1
B-1B(AB)-1 = B-1 A-1
l(AB)-1 = B-1 A-1
(AB)-1 = B-1A-1

Question 28.
verify Rolles theorem for the funciton f(x)= x2 + 2X – 8, x ∈[-4,2]
f (x) =x2 +2x – 8
1. f (x) being a polynominal function it is continuous on (-4,2)
2. Also f1 (x) = 2x + 2 hence derivable on (-4,2)
3. f(-4) = (-4)2 + 2(-4) -8 = 0
f(2) = 22 + 2(2) – 8 =0
∴ f(-4) = f(2)
∴ All three conditions of Rolle’s theorem are verified.
f1 (c) = 0
f1 (c) = 2c + 2 ⇒ 0 = 2c + 2
⇒ c = -1 ∈(-4,2)

Question 29.
If x = $$\sqrt{\mathbf{a}^{\sin ^{-1} \mathbf{t}}}$$ and $$\sqrt{\mathbf{a}^{\cos ^{-1} \mathbf{t}}}$$ then prove that $$\frac{d y}{d x}=\frac{-y}{x}$$

Question 30.
Find the two positive numbers whose sum is 15 and sum of whose squares is minimum.
x + y = 15 ⇒ y = 15 – x
s = x2 + y2 ⇒ s = x2 + (15 – x)2
$$\frac{d s}{d x}$$ = 2x + 2(15 – x) (-1)
$$\frac{d s}{d x}$$ = 0 2x – 30 + 2x
0 = 4x – 30
x = $$\frac { 30 }{ 4 }$$ = 7.5
$$\frac{d^{2} s}{d x^{2}}=2+2=4>0$$
∴ x = 7.5 require no is y = 7.5 & x = 7.5

Question 31.
Evaluate : $$\int x \tan ^{-1} x d x$$

Question 32.
Evaluate $$\int_{0}^{2} e^{x}$$ dx as a limit of a sum
$$\int_{0}^{2} e^{x}$$ .dx
= $$\left.e^{x}\right]_{0}^{2}$$ = e2 – e0 = e2 – 1

Question 33.
Find the area of the region bounded by the curve y2 = 4x and the line x = 3

Question 34.
Show that the position vector of the point P, which divides the line joining the points A and B having position vectors $$\overrightarrow{\mathrm{a}}$$ and $$\overrightarrow{\mathrm{b}}$$ internally in the ratio m : n is $$\frac{m \vec{b}+n \vec{a}}{m+n}$$

‘O’ is the fixed point, $$\overrightarrow{\mathrm{OA}}=\overrightarrow{\mathrm{a}}$$
$$\overrightarrow{\mathrm{OA}}=\overrightarrow{\mathrm{b}}$$ P divides the line AB internally in the ratio m : n

Question 35.
Show that the four points with position vectors 4î + 8ĵ + 12k̂, 2î + 4ĵ + 6k̂, 3î + 5ĵ + 4k̂ and 5î + 8ĵ + 5k̂ are coplanar.

Question 36.
Find the equation of the plane passing through the intersection of the planes 3x – y + 2z – 4 = 0 and x + y + z + 2=0 and the point (2,2,1)
Equation of plane passing through intersection of the plane is
(3x – y + 2z – 4) + λ (x + y + z + 2) = 0 This plane pass through (2,2,1)
3(2) – 2 + 2(1) -4 + λ(2 + 2 + 1 + 2)=0
2 + 7λ = 0
λ = $$\frac { -2 }{ 7 }$$
Required equqtion of plane is
(3x – y + 2z – 4) + $$\left(\frac{-2}{7}\right)$$ (x + yz + 2) + 0 [xly by 7]
21x – 7y + 14z – 28 – 2x – 2y – 2z – 4 = 0
19x – 9y + 12z = 32

Question 37.
Form the differential equation of the circles touching the x – axis at origin.
(x – h)2 +(y – k)2 = r2
(x – 0)2 +(y – k)2 =a2
x2 + y2 = 2ay ⇒ 2a = $$\frac{x^{2}+y^{2}}{y}$$
diff Equ w.r. to x

Question 38.
An insurance company insured 2000 scooter drivers, 4000 car drivers and 6000 truck drivers. The probability of an accidents are 0.01,0.03 and 0.15 respectively. One of the insured person meets with an accidents. What is the probability that he is a scooter driver?

Part-D

Answer any six questions: (6 × 5 = 30)

Question 39.
Let R+ be the set of all non- negative real numbers. Show that the function f: R+ → [4,∞)given by f(x) = x2 +4 is invertible and write the inverse of f.
f(x1) = f(x2)
X12 + 4 = X22 + 4
x1 = x2 ∴ f (x) is one-one
Let y = f(x)
y = 4x +3
x = $$\frac{y-3}{4}$$ ∈R+ ∴ f (x) is onto
Let
f-1 (x) = y
f(y) = x
4y +3 =x
$$y=\frac{x-3}{4}$$
∴ f-1 : [4,8) → R+ is defined by
f-1 (x) = $$\frac{x-3}{4}$$

Question 40.
If A = $$\left[ \begin{matrix} 1 & 2 & 3 \\ 3 & -2 & 1 \\ 4 & 2 & 1 \end{matrix} \right]$$ , then show that A3 -23A -40I = 0

Question 41.
Solve by Matrix method :
2x + 3y + 3z = 5
x – 2y + z = 5
3x – y – 2z = 3

Question 42.
If y = Aemx + Benx show that $$\frac{d^{2} y}{d x^{2}}$$ -(m + n) $$\frac{d y}{d x}$$ + mny = 0
$$\frac{d y}{d x}$$ = Ameex + Bnexn
$$\frac{d^{2} y}{d x^{2}}$$ = Am2emx + Bn2enx
$$\frac{d^{2} y}{d x^{2}}$$ – (m + n) $$\frac{d y}{d x}$$ + my
= Am2emx+ Bn2enx – m2Aemx – Amnemx – Bn2enx – mnBenn + Amnemx + mnBenx = 0

Question 43.
A particle moves along the curve 6y = x3 + 2. Find the points on the curve at which the y – coordinate is changing 8 times as fast as the x – coordinate.
6y = x3 + 2 → (l)
$$\frac{d y}{d x}=\frac{x^{2}}{2}$$
Given that $$\frac{d y}{d t}$$ = 8 $$\frac{d x}{d t}$$ ⇒ $$\frac{d x}{d t}$$ = 8
∴ 8 = $$\frac { 1 }{ 2 }$$ x2
x = ±4
put x in Equation (01) 6y = 43 + 2
∴ x = 4 y = 11
∴ x = -4 , 6y = (-4)3 + 2 ⇒ y = -10,3 points are (4,11) (-4, -10,3)

Question 44.
Find the integral of $$\frac{1}{\sqrt{x^{2}-a^{2}}}$$ with respect to x and hence evaluate $$\frac{d x}{\sqrt{x^{2}+6 x-7}}$$

Question 45.
Using integration find the area of the triangular region whose sides have the equations y = 2x + 1, y = 3x + 1 and x = 4

y = 2x – 1
points are (0,1) (1,3) (4,9) etc
x = 4, (4,0) (4,1) (4,2) etc
Area = $$\int_{0}^{4}(3 x+1), d x-\int_{0}^{4}(2 x+1), d x$$
$$A=\left(\frac{3 x^{2}}{2}+x\right)^{4}-\left(\frac{2 x^{2}}{2}+x\right)^{4}$$
A = 24 + 4 – 16 – 4 = 8 sq units

Question 46.
Solve the differential equation $$\frac{d y}{d x}+y$$ sec x = tan x,0 ≤ x < $$\frac{\pi}{2}$$
P = secx Q = tan x
IF = $$e^{\int \sec x d x}=e^{\log (\sec x+\tan x)}$$ = secx + tanx
y x IF = ∫ Q x IF
y (sec + tan x) = ∫(sec x + tan x) tan x.dx = ∫sec x.tan x + ∫ tan2 x.dx
=secx + ∫(sec2 x – 1) dx
y(sec x+tan x) = sec x + tan x – x + c

Question 47.
Derive the equation of the line in space passing through a point and parallel to a vecor both in vector and Cartesian form.

Let ‘A’ be the point, $$\overrightarrow{\mathrm{a}}$$ is P V of $$\overrightarrow{\mathrm{A}}$$
$$\overrightarrow{\mathrm{AP}}=\overrightarrow{\mathrm{OP}}-\overrightarrow{\mathrm{OA}}=\overrightarrow{\mathrm{r}}-\overrightarrow{\mathrm{a}}$$
AP is parallel to vector $$\overrightarrow{\mathrm{b}}$$
$$\overrightarrow{\mathrm{AP}}=\lambda \overrightarrow{\mathrm{b}}$$
$$\overrightarrow{\mathrm{r}}-\overrightarrow{\mathrm{a}}=\lambda \overrightarrow{\mathrm{b}}$$
$$\overrightarrow{\mathrm{r}}=\overrightarrow{\mathrm{a}}+\lambda \overrightarrow{\mathrm{b}}$$ is vector form
A=(x1 y1, z1) p (x,y,z) $$\overrightarrow{\mathrm{b}}$$ =b1i+b2j+b3k
Now $$\overrightarrow{\mathrm{r}}$$ = xi + yj + zk, $$\overrightarrow{\mathrm{a}}$$ =x1i + y1j + z1k
$$\overrightarrow{\mathrm{r}}=\overrightarrow{\mathrm{a}}+\lambda \overrightarrow{\mathrm{b}}$$ takes the form
xi + yj + zk=(x1i + y1j + z1k) + λ(b1i + b2j + b3k)
xi + yj + zk=(x1 +λb1)i+(y1 +λb2) j + (z1+ λb3)k
x =X1 +λb1 y= y1 + λb2 z = z1 + λb3

Question 48.
A die is thrown 6 times. If ‘getting an odd number’is a success, what is probability of:
a) 5 successes?
$$P(5)=6_{c_{3}}\left(\frac{1}{2}\right)^{6-5}\left(\frac{1}{2}\right)^{5}=6\left(\frac{1}{2}\right)\left(\frac{1}{32}\right)=\frac{3}{32}$$

b) at least 5 successes?
$$P(x \geq 5)=P(5)+P(6)=\left(\frac{1}{2}\right)^{6}\left[6_{C_{5}}+6_{C_{6}}\right]=\frac{6}{64}+\frac{1}{64}=\frac{7}{64}$$

c) at most successes?
P(X≤ 5) = P(0) + P(1) + P(2) + P(3) + P(4) + P(5) = $$\left(\frac{1}{2}\right)^{6}$$ [1 + 6 + 15 + 20 + 15 + 6] = $$\frac { 63 }{ 64 }$$

Part-E

Answer any one question : (1 × 10 = 10)

Question 49.
a) Prove that

and hence evaluate $$\int_{-1}^{1} \sin ^{5} x \cos ^{4} x d x$$

f(x) = sin5x.cos4x
f(-x) = sin5(-x) cos4(-x) = -sin5x.cos4x = -f(x)
∴ f is odd function, I = 0

b) prove that $$\left| \begin{matrix} { a }^{ 2 }+1 & ab & ac \\ ab & { b }^{ 2 }+1 & bc \\ ca & cb & { c }^{ 2 }+1 \end{matrix} \right|$$ = 1 + a2 + b2 + c2

Question 50.
a) A manufacturing company makes two models A and B of a product. Each piece Of model A requires 9 labour hours for fabricating and 1 labour hour for finishing. Each piece of model B requires 12 labour hours for finishing and 3 labour hours for finishing. For fabricating and finishing, the maximum labour hours available are 180 and 30 respectively. The company makes a profit of Rs. 8,000 on each piece of model A and Rs. 12,000 on each piece of model B. How many pieces of model A and model B should be manufactured per week to realize a maximum profit? What is the maximum profit per week?


text:
# blueollie

## somewhat crazy this week

I am going to have to rummage through archives for things in my personal history and talk to my bank. And I can’t forget about classes and the like.

One thing that I am thinking about: consider the two point set $F = \{0, 1 \}$ and declare each individual point to be an “open set” (this is called the “discrete topology”. ) Pretty boring, huh?

Now consider $F \times F \times F..... = \Pi^{\infty}_{i=1} F_i$ in the product topology. Seriously, this topological space is anything but boring, as simple as it appears to be. The elements of it are simply sequences of 0’s ans 1’s. There is more here.

These things appear all over the place in mathematics including in chaos theory.

Now to run and lift a little bit and get busy.

But yeah, these are all pictures which depict this space in one or more of its common forms:

## Math, abs and bench presses

Workout notes Weights first, then running.
Weights: pull ups: 10-10-10-10 (rotator cuff)
Bench: 10 x 135, 1 x 190, 1 x 180, 6 x 160 (got a spotter for 190) rotator cuff.
pull ups: 10
military (barbell); 10 x 85, 10 x 80, 10 x 80
superset with pull downs: 3 sets of 7 x 160 traditional, 7 x 100 low
rows: 3 sets of 10 with 110 (different machines and grips)

Then to the treadmill: I used on treadmill to warm up 32 minutes for 3 miles
second treadmill (passed on trying a mile): I played around with hills 1 to 2 minute intervals, 0-.5-1-2-3, etc. 32 minutes for 3 more.
It was warm in Markin and I didn’t want to overexert today.

This whole workout took just under 2 hours.

My former Congressman (from 2008 to 2012, when I was in IL-18) works out a lot and now is in a heap of trouble. Aaron Schock resigned and now is being investigated by Federal Prosecutors; his case is in front of a Grand Jury. Note: it is the Republicans that went after him.

Mathematics I worked on some…and was anguished at the elementary mistakes I made. Now if you want to see some of what world class mathematicians work on, read this. This is a “Scientific American” caliber article which shows how some work in algebra and number theory relates to string theory. The article isn’t technical but gives a flavor of what is going on.

April 10, 2015

## Somewhat recovered

It was slightly slick outside and foggy so that, plus my legs brought me to workout inside.
Track (middle lane): 7:49 (3:55/3:53)
4 lap walk, 4 lap jog (1 mile)

Weights (had to change my shirt; too sweaty):
pull ups: 15-10-10-10-(5-5) changed grip on the last set. rotator cuff recoveries.
bench: 10 x 135, 1 x 180 (ok), 6 x 160 (weak)
incline: 10 x 135

Superset:
military: 2 sets of 10 x 40 standing (dumbbells, each arm)
pull downs: 2 sets of 10 x 160 (traditional)

Superset: 3 sets of 10 x 110 row, with 10 x 90 (each arm) military, 10 x 130 pull down in between.

This wasn’t my toughest workout ever, but was good enough and I got in at least a little bit of “less glacial” running.

I spent the academic morning writing about Cantor sets and spaces, under the guise of $\Pi_{i=1}^{\infty} \{0, 1 \}_i$

April 8, 2015

## Indifference…

Workout notes: weights went fine, the run was a mental struggle.

pull ups: 5 sets of 10 (ok), rotator cuff
bench: 10 x 135, 6 x 170, 5 x 170 (rotator cuff)
incline: 10 x 135
military: 3 sets of 10 x 40 dumbbell, standing.
machine stuff: 3 sets of 10 x 110 row
machine stuff: 3 sets of 10 x 130 pull down (wide grip)
machine: 10 x 90 (each arm) military

But I was surprisingly tired and thought my run would be iffy.

Still: it all went well for the first 12 of “start at 5.5, incline 0.5, up by 0.1 mph every 4 minutes” then at 49:33, I was at mile 5 and dialed it back..walked for 30-40 seconds at 5.3 and then got back up to 59:44 (mile 6) and walked .25 cool down miles.

But I was tired when I finished; was it the dinner last night?

During the day: grading marathon, and wondering about an a math problem that is bedeviling me.

Now: watching Wichita play Southern Illinois; lots of empty seats but an entertaining game.

February 18, 2015

## Me right now: Meh

I admit that the quality of writing in this blog has suffered. It is mostly workouts, the basketball team, and not much else.

I HAVE been writing challenging stuff, but mostly here.

The challenge: present the material in a way that is most useful to the students; so some of the proofs I have use have not been the most elegant ones that a mathematics professional would use. And it has been humbling; I am finding out that I don’t know the answer to some “natural” questions.

I do have some comics that I found funny:

No, I am NOT a “people person”:

And…well…if the shoe fits:

February 17, 2015

## Taking it for granted

Workout notes running: 2 mile warm up in 20:36 (treadmill)
1 mile (middle lane, as opposed to the inner lane I used last year): 7:46 (1:58/1:55/1:55/1:56)
1 mile walk (slow)

Weights: pull ups (5 sets of 10, easy?) hip hikes, Achilles, rotator cuff rests
bench press/military press super set: bench (dumbbells) 10 x 65, 8 x 70, 8 x 70, military (dumbbell) 12 x 50 seated, supported, 2 sets of 10 x 40 standing
super set rows/pull downs: 3 sets of 10 each (110 rows, 130 pull downs, wide grip, “other machines”)

Though I thought that I felt tired going in, I felt pretty good afterward.

The run: hard enough to make me cough later (for 1-2 hours after), but not hard enough to cause pain in my teeth.
I’ve coughed after really hard runs (usually 1 mile or less; sometimes after a hard 5K when it was a 20 minute effort for me) almost all of my life..it has never been serious.

Taking it for granted
One thing about teaching the basics of a subject like topology: it reminds me of how much I take for granted when I do my own research. Yeah, I’ve worked out all of the nuances, but for many of them, it was 25-30 years ago!

February 12, 2015

enjoy. :-)

January 18, 2015

## OMG, I forgot to eat…

Yes, I presume that most people have forgotten to eat a meal at one time in their life or another, but remember I used to weigh 320 pounds.

I had one to the gym to run a bit. I ran 6 miles and walked 2; the run was 5 minutes at 5.5 mph then go up .1 mph every 5 minutes; this got me to 6 miles in 59:36) then at 1 hour, I walked for 5 minutes to get to 6.38 miles, then I got on another treadmill to walk 22:50 to finish 1.62 miles to give me 8. 1:27:50 for 8 miles was the total for running and walking.

Then I thought…dang I feel a bit hungry and realize that I had eaten nothing since waking up.

My degenerating mind: I find that when I really focus on something (say, advanced math), I get very forgetful on other basic things. I suppose that I was always a bit that way, but it is getting worse.
But there is an upside: when it comes to reviewing things that were difficult for me a long time ago, they now appear to be pretty easy to understand; it makes me wonder why I ever found them difficult to begin with. I think it is because I now have more context; more professional experience. I now see the need for details and nuance.

So in that sense, my ability to think has improved.

January 16, 2015

## The value of having walking as an activity

Workout: weights plus a 4 mile walk (55:24 for 32 laps of the outer lane; 14:25 first mile)
Weights: pull ups 5 sets (painful..NOT in an injury way…just sluggish) hip hikes, Achilles
Bench: 10 x 135, 3 x 180, 8 x 160 (out of gas…swimming yesterday?) rotator cuff
military: 3 sets of 12 x 50 dumbbells (seated, supported)
pull downs/Hammer Machine rows: 3 sets of (7 x 160 traditional, 7 x 100 low), 3 sets of 10 x 200 rows.

Then came the walk. I started to jog in the treadmill and it just didn’t “feel right”, so I was about to give up and go home and then thought: “why not walk, if you can?”

So I went to the track; the first 4 laps were 7:18 and mile was 14:25…then I felt better. 13:43, 13:30, 13:45 were my other miles (slightly longer actually).

No, it wasn’t hard, and shouldn’t have been. But it was better than ZERO.

Now: I need to complete my syllabi and to do other chores.

I am teaching a class on elementary topology. I had mentioned what a challenge it will be as I can’t “remember” a time during my professional life when I didn’t know this stuff. And I haven’t taught this course before, nor have I had a conversation about these topics with anyone but an active research mathematician in well over 20 years. But like it was new to me in 1980 (when I had my first course), it is going to be new to them.

And I have an excuse to take time to relearn some of the “fun stuff” that I haven’t used in a while. It is kind of fun to easily understand stuff that used to baffle me.

Oh, I am teaching two other courses; they are elementary by comparison but they are follow on courses to previous calculus courses. These students deserve a professional effort from me, so I can’t get so excited about FINALLY getting to teach something related to (most of) my own research that I ignore these classes.

January 15, 2015

## Circular illusions and camouflaged frogs

Can you spot the frogs? Clicking the link will take you Mathew Cobb’s post at Why Evolution is True (photo by Nash Turley)

I’m sure that you can, but this photo shows what evolutionary adaptation can do.

Also, WEIT provided a link to this little gem: these “rotating dots” are, individually, moving along a straight line path. Seriously…all of them are.

I am going to try to write some equations that describe this motion.

January 6, 2015

format: plain


text:
copy number variation
1
0
Entering edit mode
3.5 years ago
v27 ▴ 10

I want to detect copy number variation in fungi data (paired-end, Illumina data). The data is as following:2 sensitive 2 resistant strains 1 reference

Could someone suggest me a tool for detecting CNV.

copy number variation • 834 views
0
Entering edit mode

Did you see Copy Number Variation Tools question that was asked before ?

0
Entering edit mode
3.3 years ago

Just map the known genes on processed reads and note down the number of times they aligned. Use appropriate alignmnet parameters. You can use bowtie aligner. At last you will have number of times each gene aligned in both samples. Relatively, you can conclude on gene copy number variation, provided that the sequencing depth is same for both the samples.


text:
# Git diff images and pdfs

Git is a fantastic tool to version control code. And the advantages of version controlling my work are so evident that I want to version control everything else I do besides code. Most of my work consists of editing text files, and I have even forced my workflow into text files just to be able to version control more of it. Thus, I keep track of my source code, org-mode notes and then some $$\LaTeX$$ files.

#### Óscar Nájera

Data Scientist, Hacker & Recovering Physicists

PhD in Theoretical Physics

The world


text:
GeoSci 236: Gram-Schmidt Orthogonalization

Gidon Eshel
491 Hinds
Dept. of the Geophysical Sciences,
5734 S. Ellis Ave., The Univ. of Chicago,
Chicago, IL 60637
(773) 702-0440, geshel@midway.uchicago.edu

If we have a set of linearly-independent but non-orthogonal vectors , , we often wish to turn them into an alternative set of vectors, , , that are mutually orthonormal,

Achieving this orthonormalization is the purpose of the Gram-Schmidt procedure.

Let's address the particular example of

The first is simple, involving a simple normalization;

The second vector will be the original second vector, , minus its projection on the first orthonormal basis vector, . That is,

which, upon normalization to unit norm, becomes

To construct the last basis vector, we need to subtract from its projections on both and ;

Sparing you the straightforward yet tedious arithmetic,

which, when normalized, becomes

To test the results, we need to make sure that

as required.

In conclusion, we have transformed our original, non-orthonormal, basis set,

to an entirely equivalent set, whose vectors are all mutually orthogonal and have unit norms. Now, when we express an arbitrary vector from the space spanned by these 2 alternative sets as a linear combination of the orthonormal vectors , and , the projections (the weights) are entirely independent of one another, and their sum is exactly the norm of the represented vector, and not more. This is the reason orthonormalization of the basis vectors is very useful.


text:
# Why can't a set have two elements of the same value?

Suppose I have two sets, $A$ and $B$:

$$A = \{1, 2, 3, 4, 5\} \\ B = \{1, 1, 2, 3, 4\}$$

Set $A$ is valid, but set $B$ isn’t because not all of its elements are unique. My question is, why can’t sets contain duplicate elements?

Edit: After reading some of the answers and comments, set $B$ is valid, it’s just equal to the below instead of the above.

$$B = \{1,2,3,4\}$$

Note: this is all based on what I learned, so this may seem easy to some, or even incorrect, but it’s a question I would really like to find the answer to.

#### Solutions Collecting From Web of "Why can't a set have two elements of the same value?"

The short, perhaps unsatisfying answer is, because that is how they are defined. The long answer is that, in most cases, that is what is useful.

For other cases, there is also a theory built around multisets, which are like sets except they allow multiplicity.

I’d say that $B$ is valid and equal to $\{1, 2, 3, 4\}$.

The notation $B = \{1, 1, 2, 3, 4\}$ gives $B$ by listing its elements:

$1 \in B$

$1 \in B$

$2 \in B$

$3 \in B$

$4 \in B$

Clearly saying twice that $1 \in B$ is harmless.

This is the axiom of extensionality: two sets are equal iff they have the same elements.

Do not think of 1 and 1 as “two elements of the same value”. They are the same element really. And an element is either a member of a set or it is not.

Informally, the “set” of members of your household should have a well defined size, and the number of nicknames a person has is unimportant to that set.

It’s just agreed by convention that no matter how many labels for the same thing we try to include in a set, the set only contains the things themselves. You refer to 1 twice, but that’s just repeating the name of the thing, and by definition, the set only contains the things themselves.

If we had a ‘set’ $U$ defined to be $\{1,2,3\}$, could we have another set $V = \{1,1,2,3\}$ where $U\neq V$?

Yes. We can do this, but using this notation makes it ambiguous and nasty.

We need to be careful about what we mean when we say $=$. Let’s let $=_S$ denote an equivalence relation on sets, and $=_n$ be the usual equivalence relation of numbers.

It is perfectly consistent to talk about $U,V$, but if we write it down like this we’ve labeled everything using the weaker relation $=_n$, making it a big mess. I’ll show you what I mean:

If $a,b$ are two distinct elements in $V$ where $a=_n 1$ and $b=_n 1$, then $a=_nb$. Furthermore, if we choose the $c \in U$ where $c=_n1$, then $a =_n b =_n c$.

We want $U\neq _S V$, so we must have that $\{a\} \neq_S \{b\}$. We have no idea whether or not $\{c\}=_S \{a\}$ or $\{b\}$. In fact, it might not even be equal (in the set sense) to either of them.

With this knowlege we can re-label the $1$s in our sets: $U=\{1_c, 2, 3\}$, and $V=\{1_a, 1_b, 2, 3\}$. But we still don’t have any idea whether or not $1_c$ as a set element is the same as $1_a$ or $1_b$. The same can be said for $U$’s $2$ and $3$ vs $V$’s $2$ and $3$.

Under this notation we have no idea how $=_S$ works comparing elements across sets.

Here’s a better way to do it. Instead of worrying about the set relation, define U and V using an index.

To start, clarify that every time you write down $a_i$, $i\in \mathbb{N}$, you are talking about the exact same object $a_i$, in every context. This forces the following property: $\{a_i\} =_S \{a_i\}$.

Now define $a_1 =_n 1\in \mathbb{N}; a_2 =_n 1 \in \mathbb{N}; a_3 =_n 2 \in \mathbb{N}; a_4 =_n 3 \in \mathbb{N}$, and let $U=\{a_1, a_2, a_3, a_4\}, V=\{a_2, a_3, a_4\}$

What we have really done now is make a function from the set $\{1,2,3,4\}\subset \mathbb{N}$ into the set $\{1,2,3\}\subset\mathbb{N}$, and defined $U, V$ in terms of that function. Under this description the $=_S$ relation is well-defined.

To say $2$ sets are equal, show that each set is contained in the other. $\{1,1,2,3,4\} = \{1,2,3,4\}$ since any element on the left can be found on the right and vice-versa.

The axioms of the Set Theory do not allow us to distinguish between two sets like $A = \{1,2\}$ and $B = \{1,1,2\}$. And every sentence valid about sets should be derived in some way from the axioms.

Explained:

The logic of the set theory is extensional, that means that doesn’t matter the nature of a set, just its extension. The set $A = \{1,1,2,3,4\}$ could be considered different from $B = \{1,2,3,4\}$ in intension, but they are not different in extension, since $1 = 1$, both sets have the same elements. Even if one instance of the number $1$ precedes the other, the axioms of the set theory do not allow to distinguish between two sets using the order of its elements, because the notion of order is not defined by the axioms of the theory. To do that, the ordered pair is defined as follows: $$\left(a,b\right) \equiv \{\{a\},\{a,b\}\}$$ Thus $\left(a,b\right) \neq \left(b,a\right)$ since $\{\{a\},\{a,b\}\} \neq \{\{b\},\{b,a\}\}$. Thus, the set $A$ can’t be distinguished fom B using its order. Moreover, the cardinality of two sets is never used to prove that two sets are different.

What about the ordered pair $\left(1,1\right) \equiv \{\{1\},\{1,1\}\}$? Since $1 = 1$ we have $\{1,1\} \equiv \{1\}$, this pair is a well known structure called singlenton, obtained as a consequence of the axiom of pairing and (as you can see) the axiom of extension. Moreover, since $\{1\}$ is present in $\left(1,1\right)$ two times, $\left(1,1\right) \equiv \{\{1\}\}$ another singlenton. Which is not a problem for the Analysis in $\mathbb{R}^2$, because this pair is different from $\{1\}$, a subset of $\mathbb{R}$, and different from each other pair in $\mathbb{R}^2$. The moral of this story is that you can’t distinguish between the first and the second element of $\left(1,1\right)$, and it’s ok.

Although the symbol “$\equiv$” is used to introduce syntactic abbreviations instead of semantic equality denoted by “$=$”, this difference is just important in the study of Formal Languages, but not really important for this case, since the axiom of extension is what allows us to consider $\{1,1\} \equiv \{1\}$ as $\{1,1\} = \{1\}$. Just read the Section 3 of the book Naive Set Theory of Paul R. Halmos, what introduces the term singlenton in that way, and that’s how is used by the specialized literature.

Other reference to understand the difference between intension and extension.

https://plato.stanford.edu/entries/logic-intensional/

The problem here is one of equating the definition of a set with its representation. The fact that you can kind of represent a set on paper doesn’t mean that that representation is the set. So, for example, I can talk about the set that only contains the number we call one, and I can make this concrete by writing it thus: $\{1\}$. If I then wrote $\{1, 2\}$ and said that this is the same set then you would correctly object; but if I wrote $\{1, 1\}$ and said that this was the same set then you should not object because that depiction satisfies the definition.

It’s like having the definition of $\pi$ as the ratio of a circle’s circumference to its diameter and then writing a number like 3.14159 and saying that the number is $\pi$ – $\pi$ is the definition and the number is what we write to represent $\pi$, and that representation can be imprecise or deficient.


text:
# ankursinha.in/blog

neuroscience/fedora/musings

Tue 18 August 2009

# Campaign to get more folks to use Fedora

Posted by ankur in Tech (85 words, approximately a 1 minute read)

So, two of us, Ambassadors here at Manipal are starting a sort of a campaign to increase the number of students using Fedora in college.

This is the first part of the campaign: The poster ;)

I'll keep the blog updated with the other steps that we take. If there are …

Sat 15 August 2009

# fpaste : A simple tool for posting info onto fpaste.org

Posted by ankur in Tech (128 words, approximately a 1 minute read)

Hi folks,

An announcement regarding fpaste : A simple tool for posting info onto fpaste.org.

It's a python script that enables you to paste the output of a command, or a file to fpaste.org. For those who are unaware of what fpaste.org is, please click the link ;). It's …

Wed 05 August 2009

# How awesome is this??

Posted by ankur in Tech (59 words, approximately a 1 minute read)

AWESOME AWESOME AWESOME!!! That's all I can say..

...

...

(31/32):
xulrunner-devel-1.9.1.1-1.fc11_1.9.1.2-1.fc11.x86_64.drpm 675 kB 00:22
(32/32): yelp-2.26.0-5.fc11_2.26.0-6.fc11.x86_64.drpm 150 kB 00:05
Finishing rebuild of rpms, from deltarpms 90 MB 00:04 …

Sat 01 August 2009

# My worst turned best day with Fedora

Posted by ankur in Tech (230 words, approximately a 1 minute read)

Okay, so I finally decided to take it up a notch.

I was going to update F10->F11.  Choices? Preupgrade, clean reinstall.

Preupgrade failed on me (because I have a separate / partition which fell short on space)

Clean reinstall: Problems::  I don't trust me DVD drive. Netinstall was outa the …

Tue 07 July 2009

# First commit for twit_tui on github.

Posted by ankur in Tech (45 words, approximately a 1 minute read)

I logged into github for the first time and put twit_tui up there. Even though I don't intend any further development on the app, I thought it might just be a good idea (teaches me how to use git properly etc.)

Have a look :: http://github.com/sanjayankur31/twit_tui/tree …

Tue 07 July 2009

# GyachI. Another one of 'em bugs??

Posted by ankur in Tech (58 words, approximately a 1 minute read)

I *think* I've unearthed another one of 'em bugs. Here it is.

Beforehitting "Refresh friend list"

After hitting "Refresh friends list":

Notice the difference?? "Refresh friends list" just shows everybody offline. I'm sure it isn't supposed to happen that way. Anyone else try this and check?? The only thing …

Tue 07 July 2009

# GyachI. Another one of 'em bugs??

Posted by ankur in Tech (58 words, approximately a 1 minute read)

I *think* I've unearthed another one of 'em bugs. Here it is.

Beforehitting "Refresh friend list"

After hitting "Refresh friends list":

Notice the difference?? "Refresh friends list" just shows everybody offline. I'm sure it isn't supposed to happen that way. Anyone else try this and check?? The only thing …

Mon 06 July 2009

# GyachI trouble

Posted by ankur in Tech (95 words, approximately a 1 minute read)

I was happy using GyachI for my Yahoo messenger needs. Ran outa luck. People do not receive my messages when I use GyachI. Reinstalled, removed config files, no difference, they still don't get my messages.

I've switched to Empathy for the time being. But, I miss the webcam feature that …

Sat 04 July 2009

# F-spot ..

Posted by ankur in Tech (26 words, approximately a 1 minute read)

I've been getting a lot of this error lately while uploading photos to my picasa webalbum using F-spot. Just curious, anyone know what the error means?


text:
# irfpy.util.collision¶

Handles collision.

Note

YF has old module handling ratherford scattering. I haven’t ported it, but can be done on request.

irfpy.util.collision.binary_collision(mass1, pos1, vel1, mass2, pos2, vel2, collision_length)[source]

Calculate the binary collision

Parameters
• mass1 – Mass of the particle 1

• pos1 – Postion vector of the particle 1

• vel1 – Velocity vector of the particle 1

• mass2 – Mass of the particle 2

• pos2 – Postion vector of the particle 2

• vel2 – Velocity vector of the particle 2

irfpy.util.collision.binary_collision_stationary_vector1(mass1, pos1, vel1, mass2, collision_length)[source]

Slightly generalized version of binary_collision_stationary()

Calculate the final velocity after the binary collision.

This function accepts the position and velocity vectors of particle 1. Particle 2 should be origin, and stationary. If the negative relative velocity (particles 1 and 2 separates as time goes), a collision will not happen.

Other conditions are hold as binary_collision_stationary(). (e.g. Particle 2 should be at origin, and stationary.)

irfpy.util.collision.binary_collision_stationary(mass1, speed1, mass2, impact_parameter, collision_length)[source]

Cancluate a binary collision in one-particle stationary system.

Parameters
• mass1 – Mass of moving particle, m1

• speed1 – Speed of the moving particle, v1. Positive.

• mass2 – Mass of stationary particle, m2

• impact_parameter – The impact parameter, d. Positive.

• collision_length – The radius of the cross section, or r1+r2 where r1 is the radius of the moving particke and r2 is the radius of the stationary particle.

Returns

(V1, W1, V2, W2)

A binary collision is simulated here. Situation is that a flying (incoming) particle 1 has mass1 with speed 1 (positive y component) in the (negative x, positive y) quadrant. The stationary particle 2 at the origin will be collided. The returned is the final velocity (x, y components). If the impact paramter is more than the collision_length, the particle will not collide.

Theory

A binary collision is characterized by the two particles with masses, m1 and m2.

Let’s be in a system where the second particle with m2 is in rest at the origin. This system change be chosen without losing the generality.

First particle (with m1) flies from infinite -x, toward the origin, with a speed of v1 along x axis. Just by rotation, we can select a frame that the first particle is in the (-x, +y) quadrant, center in z=0 plane, with v1>0 with only vx component.

Then, after the collision, the motion of two particles should be confined in x-y plane since no force acting in the z direction. Assume the resulting velocity vector as (V1, W1) for particle m1, and (V2, W2) for particle m2.

Momentum conservation will give you

$m_1 v_1 = m_1 V_1 + m_2 V_2$

and

$0 = m_1 W_1 + m_2 W_2$

Energy conservation will give you

$m_1 v_1^2 = m_1 V_1^2 + m_1 W_1^2 + m_2 V_2^2 + m_2 W_2^2$

The force only act on the collision, so that the particle m2 should have the following geometric relation of velocity.

$W_2 = -\frac{d}{\sqrt{(r_1+r_2)^2 - d^2}} V_2$

Solving above four equations to derive the V1, W1, V2 and W2. For simplicity, we use the following notations.

$\begin{split}\mu &= \frac{m_2}{m_1} \\ \delta &= \frac{d}{\sqrt{(r_1+r_2)^2 - d^2}} \\ \alpha &= (\mu+1)(1+\delta^2)\end{split}$

The solutions are

$\begin{split}V_1 &= v_1 (1 - \frac{2\mu}{\alpha}) \\ W_1 &= \frac{2v_1\mu\delta}{\alpha} \\ V_2 &= \frac{2v_1}{\alpha} \\ W_2 &= -\frac{2v_1\delta}{\alpha} \\\end{split}$

Todo

To check the above formulation is correct. In particular the fourth equation should be checked. How to? Probably we may need another formulation using center of gravity system…


text:
Author Topic: QUIZ3 TUT 0502  (Read 622 times)

Xinyu Jing

• Jr. Member
• Posts: 11
• Karma: 0
QUIZ3 TUT 0502
« on: October 12, 2019, 12:20:07 AM »
Question: 𝑐𝑜𝑠(𝑡)𝑦″+𝑠𝑖𝑛(𝑡)𝑦′−𝑡𝑦=0
Find the Wronskian of two solutions of the given differential equation without solving the equation.

Solution:
Divide both sides by 𝑐𝑜𝑠(𝑡)
𝑦″+𝑡𝑎𝑛(𝑡)𝑦′−𝑡𝑐𝑜𝑠(𝑡)𝑦=0
𝑊(𝑦1,𝑦2)(𝑡)=𝑐𝑒−∫𝑝(𝑡)𝑑𝑡
𝑊(𝑦1,𝑦2)(𝑡)=𝑐𝑒−∫𝑡𝑎𝑛(𝑡)𝑑𝑡=𝑐𝑒−(−𝑙𝑛|𝑐𝑜𝑠(𝑡)|)
𝑊(𝑦1,𝑦2)(𝑡)=𝑐𝑒𝑙𝑛|𝑐𝑜𝑠(𝑡)|=𝑐𝑐𝑜𝑠(𝑡)

Therefore, the Wronskian of any pair of solutions of the given equation is 𝑊(𝑦1,𝑦2)(𝑡)=𝑐𝑐𝑜𝑠(𝑡)


text:
# CNTK 202: Language Understanding with Recurrent Networks¶

This tutorial shows how to implement a recurrent network to process text, for the Air Travel Information Services (ATIS) task of slot tagging (tag individual words to their respective classes, where the classes are provided as labels in the training data set).

There are 2 parts to this tutorial: - Part 1: We will tag each word in a sequence to their corresponding label - Part 2: We will classify a sequence to its corresponding intent.

We will start with a straight-forward (linear) embedding of the words followed by a recurrent LSTM to label each word in a sequence to the corresponding class. We will show how to classify each word token in a sequence to the corresponding class. This will then be extended to include neighboring words and run bidirectionally.

We will take the last state of the sequence and train a model that classifies the entire sequence to the corresponding class label (in this case the intent associated with the sequence).

The techniques you will practice are: * model description by composing layer blocks, a convenient way to compose networks/models without requiring the need to write formulas, * creating your own layer block * variables with different sequence lengths in the same network * training the network

We assume that you are familiar with basics of deep learning, and these specific concepts: * recurrent networks (Wikipedia page) * text embedding (Wikipedia page)

## Prerequisites¶

We assume that you have already installed CNTK. This tutorial requires CNTK V2. We strongly recommend to run this tutorial on a machine with a capable CUDA-compatible GPU. Deep learning without GPUs is not fun.

In this tutorial, we are going to use a (lightly preprocessed) version of the ATIS dataset. You can download the data automatically by running the cells below or by executing the manual instructions.

Fallback manual instructions Download the ATIS training and test files and put them at the same folder as this notebook. If you want to see how the model is predicting on new sentences you will also need the vocabulary files for queries and slots

In [1]:

from __future__ import print_function # Use a function definition from future version (say 3.x from 2.7 interpreter)
import requests
import os

response = requests.get(url, stream=True)
with open(filename, "wb") as handle:
for data in response.iter_content():
handle.write(data)

locations = ['Tutorials/SLUHandsOn', 'Examples/LanguageUnderstanding/ATIS/BrainScript']

data = {
'train': { 'file': 'atis.train.ctf', 'location': 0 },
'test': { 'file': 'atis.test.ctf', 'location': 0 },
'query': { 'file': 'query.wl', 'location': 1 },
'slots': { 'file': 'slots.wl', 'location': 1 },
'intent': { 'file': 'intent.wl', 'location': 1 }
}

for item in data.values():
location = locations[item['location']]
path = os.path.join('..', location, item['file'])
if os.path.exists(path):
print("Reusing locally cached:", item['file'])
# Update path
item['file'] = path
elif os.path.exists(item['file']):
print("Reusing locally cached:", item['file'])
else:
url = "https://github.com/Microsoft/CNTK/blob/release/2.6/%s/%s?raw=true"%(location, item['file'])

Reusing locally cached: query.wl
Reusing locally cached: intent.wl
Reusing locally cached: atis.test.ctf
Reusing locally cached: atis.train.ctf
Reusing locally cached: slots.wl

Importing libraries: CNTK, math and numpy

CNTK’s Python module contains several submodules like io, learner, and layers. We also use NumPy in some cases since the results returned by CNTK work like NumPy arrays.

In [2]:

import math
import numpy as np

import cntk as C
import cntk.tests.test_utils
cntk.tests.test_utils.set_device_from_pytest_env() # (only needed for our build system)
C.cntk_py.set_fixed_random_seed(1) # fix a random seed for CNTK components

The task we want to approach in this tutorial is slot tagging. We use the ATIS corpus. ATIS contains human-computer queries from the domain of Air Travel Information Services, and our task will be to annotate (tag) each word of a query whether it belongs to a specific item of information (slot), and which one.

The data in your working folder has already been converted into the “CNTK Text Format.” Let us look at an example from the test-set file atis.test.ctf:

19  |S0 178:1 |# BOS      |S1 14:1 |# flight  |S2 128:1 |# O
19  |S0 770:1 |# show                         |S2 128:1 |# O
19  |S0 429:1 |# flights                      |S2 128:1 |# O
19  |S0 444:1 |# from                         |S2 128:1 |# O
19  |S0 272:1 |# burbank                      |S2 48:1  |# B-fromloc.city_name
19  |S0 851:1 |# to                           |S2 128:1 |# O
19  |S0 789:1 |# st.                          |S2 78:1  |# B-toloc.city_name
19  |S0 564:1 |# louis                        |S2 125:1 |# I-toloc.city_name
19  |S0 654:1 |# on                           |S2 128:1 |# O
19  |S0 601:1 |# monday                       |S2 26:1  |# B-depart_date.day_name
19  |S0 179:1 |# EOS                          |S2 128:1 |# O

This file has 7 columns:

• a sequence id (19). There are 11 entries with this sequence id. This means that sequence 19 consists of 11 tokens;
• column S0, which contains numeric word indices; the input data is encoded in one-hot vectors. There are 943 words in the vocabulary, so each word is a 943 element vector of all 0 with a 1 at a vector index chosen to represent that word. For example the word “from” is represented with a 1 at index 444 and zero everywhere else in the vector. The word “monday” is represented with a 1 at index 601 and zero everywhere else in the vector.
• a comment column denoted by #, to allow a human reader to know what the numeric word index stands for; Comment columns are ignored by the system. BOS and EOS are special words to denote beginning and end of sentence, respectively;
• column S1 is an intent label, which we will use in the second part of the tutorial;
• another comment column that shows the human-readable label of the numeric intent index;
• column S2 is the slot label, represented as a numeric index; and
• another comment column that shows the human-readable label of the numeric label index.

The task of the neural network is to look at the query (column S0) and predict the slot label (column S2). As you can see, each word in the input gets assigned either an empty label O or a slot label that begins with B- for the first word, and with I- for any additional consecutive word that belongs to the same slot.

### Model Creation¶

The model we will use is a recurrent model consisting of an embedding layer, a recurrent LSTM cell, and a dense layer to compute the posterior probabilities:

slot label   "O"        "O"        "O"        "O"  "B-fromloc.city_name"
^          ^          ^          ^          ^
|          |          |          |          |
+-------+  +-------+  +-------+  +-------+  +-------+
| Dense |  | Dense |  | Dense |  | Dense |  | Dense |  ...
+-------+  +-------+  +-------+  +-------+  +-------+
^          ^          ^          ^          ^
|          |          |          |          |
+------+   +------+   +------+   +------+   +------+
0 -->| LSTM |-->| LSTM |-->| LSTM |-->| LSTM |-->| LSTM |-->...
+------+   +------+   +------+   +------+   +------+
^          ^          ^          ^          ^
|          |          |          |          |
+-------+  +-------+  +-------+  +-------+  +-------+
| Embed |  | Embed |  | Embed |  | Embed |  | Embed |  ...
+-------+  +-------+  +-------+  +-------+  +-------+
^          ^          ^          ^          ^
|          |          |          |          |
w      ------>+--------->+--------->+--------->+--------->+------...
BOS      "show"    "flights"    "from"   "burbank"

Or, as a CNTK network description. Please have a quick look and match it with the description above: (descriptions of these functions can be found at: the layers reference)

In [3]:

# number of words in vocab, slot labels, and intent labels
vocab_size = 943 ; num_labels = 129 ; num_intents = 26

# model dimensions
input_dim  = vocab_size
label_dim  = num_labels
emb_dim    = 150
hidden_dim = 300

# Create the containers for input feature (x) and the label (y)
x = C.sequence.input_variable(vocab_size)
y = C.sequence.input_variable(num_labels)

def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim, name='embed'),
C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_labels, name='classify')
])

Now we are ready to create a model and inspect it.

The model attributes are fully accessible from Python. The first layer named embed is an Embedding layer. Here we use the CNTK default, which is linear embedding. It is a simple matrix with dimension (input word encoding x output projected dimension). You can access its parameter E (where the embeddings are stored) like any other attribute of a Python object. Its shape contains a -1 which indicates that this parameter (with input dimension) is not fully specified yet, while the output dimension is set to emb_dim ( = 150 in this tutorial).

Additionally, we also inspect the value of the bias vector in the Dense layer named classify. The Dense layer is a fundamental compositional unit of a Multi-Layer Perceptron (as introduced in CNTK 103C tutorial). The Dense layer has both weight and bias parameters, one each per Dense layer. Bias terms are by default initialized to 0 (but there is a way to change that if you need). As you create the model, one should name the layer component and then access the parameters as shown here.

Suggested task: What should be the expected dimension of the weight matrix from the layer named classify? Try printing the weight matrix of the classify layer? Does it match with your expected size?

In [4]:

# peek
z = create_model()
print(z.embed.E.shape)
print(z.classify.b.value)

(-1, 150)
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.]

In our case we have input as one-hot encoded vector of length 943 and the output dimension emb_dim is set to 150. In the code below we pass the input variable x to our model z. This binds the model with input data of known shape. In this case, the input shape will be the size of the input vocabulary. With this modification, the parameter returned by the embed layer is completely specified (943, 150). Note: You can initialize the Embedding matrix with pre-computed vectors using Word2Vec or GloVe.

In [5]:

# Pass an input and check the dimension
z = create_model()
print(z(x).embed.E.shape)

(943, 150)

To train and test a model in CNTK, we need to create a model and specify how to read data and perform training and testing.

In order to train we need to specify:

• how to read the data
• the model function, its inputs, and outputs
• hyper-parameters for the learner such as the learning rate

We already looked at the data. But how do you generate this format? For reading text, this tutorial uses the CNTKTextFormatReader. It expects the input data to be in a specific format, as described here.

For this tutorial, we created the corpora by two steps: * convert the raw data into a plain text file that contains of TAB-separated columns of space-separated text. For example:

BOS show flights from burbank to st. louis on monday EOS (TAB) flight (TAB) O O O O B-fromloc.city_name O B-toloc.city_name I-toloc.city_name O B-depart_date.day_name O

This is meant to be compatible with the output of the paste command. * convert it to CNTK Text Format (CTF) with the following command:

python [CNTK root]/Scripts/txt2ctf.py --map query.wl intent.wl slots.wl --annotated True --input atis.test.txt --output atis.test.ctf where the three .wl files give the vocabulary as plain text files, one word per line.

In these CTF files, our columns are labeled S0, S1, and S2. These are connected to the actual network inputs by the corresponding lines in the reader definition:

In [6]:

def create_reader(path, is_training):
return C.io.MinibatchSource(C.io.CTFDeserializer(path, C.io.StreamDefs(
query         = C.io.StreamDef(field='S0', shape=vocab_size,  is_sparse=True),
intent        = C.io.StreamDef(field='S1', shape=num_intents, is_sparse=True),
slot_labels   = C.io.StreamDef(field='S2', shape=num_labels,  is_sparse=True)
)), randomize=is_training, max_sweeps = C.io.INFINITELY_REPEAT if is_training else 1)

In [7]:

# peek

Out[7]:

dict_keys(['query', 'slot_labels', 'intent'])

## Training¶

We also must define the training criterion (loss function), and also an error metric to track. In most tutorials, we know the input dimensions and the corresponding labels. We directly create the loss and the error functions. In this tutorial we will do the same. However, we take a brief detour and learn about placeholders. This concept would be useful for Task 3.

Learning note: Introduction to placeholder: Remember that the code we have been writing is not actually executing any heavy computation it is just specifying the function we want to compute on data during training/testing. And in the same way that it is convenient to have names for arguments when you write a regular function in a programming language, it is convenient to have placeholders that refer to arguments (or local computations that need to be reused). Eventually, some other code will replace these placeholders with other known quantities in the same way that in a programming language the function will be called with concrete values bound to its arguments.

Specifically, the input variables you have created above x = C.sequence.input_variable(vocab_size) holds data pre-defined by vocab_size. In the case where such instantiations are challenging or not possible, using placeholder is a logical choice. Having the placeholder only allows you to defer the specification of the argument at a later time when you may have the data.

Here is an example below that illustrates the use of placeholder.

In [8]:

def create_criterion_function(model):
labels = C.placeholder(name='labels')
ce   = C.cross_entropy_with_softmax(model, labels)
errs = C.classification_error      (model, labels)
return C.combine ([ce, errs]) # (features, labels) -> (loss, metric)

criterion = create_criterion_function(create_model())
criterion.replace_placeholders({criterion.placeholders[0]: C.sequence.input_variable(num_labels)})

Out[8]:

Composite(Combine): Input('Input2300', [#, *], [129]), Placeholder('labels', [???], [???]) -> Output('Block2270_Output_0', [#, *], [1]), Output('Block2290_Output_0', [#, *], [])

While the cell above works well when one has input parameters defined at network creation, it compromises readability. Hence we prefer creating functions as shown below

In [9]:

def create_criterion_function_preferred(model, labels):
ce   = C.cross_entropy_with_softmax(model, labels)
errs = C.classification_error      (model, labels)
return ce, errs # (model, labels) -> (loss, error metric)

In [10]:

def train(reader, model_func, max_epochs=10, task='slot_tagging'):

# Instantiate the model function; x is the input (feature) variable
model = model_func(x)

# Instantiate the loss and error function
loss, label_error = create_criterion_function_preferred(model, y)

# training config
epoch_size = 18000        # 18000 samples is half the dataset size
minibatch_size = 70

# LR schedule over epochs
# In CNTK, an epoch is how often we get out of the minibatch loop to
# do other stuff (e.g. checkpointing, adjust learning rate, etc.)
lr_per_sample = [3e-4]*4+[1.5e-4]
lr_per_minibatch = [lr * minibatch_size for lr in lr_per_sample]
lr_schedule = C.learning_parameter_schedule(lr_per_minibatch, epoch_size=epoch_size)

# Momentum schedule
momentums = C.momentum_schedule(0.9048374180359595, minibatch_size=minibatch_size)

# We use a the Adam optimizer which is known to work well on this dataset
# Feel free to try other optimizers from
# https://www.cntk.ai/pythondocs/cntk.learner.html#module-cntk.learner
lr=lr_schedule,
momentum=momentums,

# Setup the progress updater
progress_printer = C.logging.ProgressPrinter(tag='Training', num_epochs=max_epochs)

# Uncomment below for more detailed logging
#progress_printer = ProgressPrinter(freq=100, first=10, tag='Training', num_epochs=max_epochs)

# Instantiate the trainer
trainer = C.Trainer(model, (loss, label_error), learner, progress_printer)

# process minibatches and perform model training
C.logging.log_number_of_parameters(model)

# Assign the data fields to be read from the input
else:

t = 0
for epoch in range(max_epochs):         # loop over epochs
epoch_end = (epoch+1) * epoch_size
while t < epoch_end:                # loop over minibatches on the epoch
data = reader.next_minibatch(minibatch_size, input_map= data_map)  # fetch minibatch
trainer.train_minibatch(data)               # update model with it
t += data[y].num_samples                    # samples so far
trainer.summarize_training_progress()

Run the trainer

You can find the complete recipe below.

In [11]:

def do_train():
global z
z = create_model()
do_train()

Training 721479 parameters in 6 parameter tensors.
Learning rate per minibatch: 0.020999999999999998
Finished Epoch[1 of 10]: [Training] loss = 1.740198 * 18010, metric = 28.02% * 18010 6.466s (2785.3 samples/s);
Finished Epoch[2 of 10]: [Training] loss = 0.665177 * 18051, metric = 14.30% * 18051 5.238s (3446.2 samples/s);
Finished Epoch[3 of 10]: [Training] loss = 0.526256 * 17941, metric = 11.34% * 17941 5.198s (3451.5 samples/s);
Finished Epoch[4 of 10]: [Training] loss = 0.395405 * 18059, metric = 8.22% * 18059 5.329s (3388.8 samples/s);
Learning rate per minibatch: 0.010499999999999999
Finished Epoch[5 of 10]: [Training] loss = 0.293512 * 17957, metric = 6.20% * 17957 5.106s (3516.8 samples/s);
Finished Epoch[6 of 10]: [Training] loss = 0.264932 * 18021, metric = 5.73% * 18021 5.335s (3377.9 samples/s);
Finished Epoch[7 of 10]: [Training] loss = 0.217258 * 17980, metric = 4.69% * 17980 5.248s (3426.1 samples/s);
Finished Epoch[8 of 10]: [Training] loss = 0.209614 * 18025, metric = 4.55% * 18025 5.139s (3507.5 samples/s);
Finished Epoch[9 of 10]: [Training] loss = 0.165851 * 17956, metric = 3.84% * 17956 5.636s (3185.9 samples/s);
Finished Epoch[10 of 10]: [Training] loss = 0.157653 * 18039, metric = 3.41% * 18039 5.646s (3195.0 samples/s);

This shows how learning proceeds over epochs (passes through the data). For example, after four epochs, the loss, which is the cross-entropy criterion, has reduced significantly as measured on the ~18000 samples of this epoch, and the same with the error rate on those same 18000 training samples.

The epoch size is the number of samples–counted as word tokens, not sentences–to process between model checkpoints.

Once the training has completed (a little less than 2 minutes on a Titan-X or a Surface Book), you will see an output like this

Finished Epoch[10 of 10]: [Training] loss = 0.157653 * 18039, metric = 3.41% * 18039

which is the loss (cross entropy) and the metric (classification error) averaged over the final epoch.

On a CPU-only machine, it can be 4 or more times slower. You can try setting

emb_dim    = 50
hidden_dim = 100

to reduce the time it takes to run on a CPU, but the model will not fit as well as when the hidden and embedding dimension are larger.

### Evaluating the model¶

Like the train() function, we also define a function to measure accuracy on a test set by computing the error over multiple minibatches of test data. For evaluating on a small sample read from a file, you can set a minibatch size reflecting the sample size and run the test_minibatch on that instance of data. To see how to evaluate a single sequence, we provide an instance later in the tutorial.

In [12]:

def evaluate(reader, model_func, task='slot_tagging'):

# Instantiate the model function; x is the input (feature) variable
model = model_func(x)

# Create the loss and error functions
loss, label_error = create_criterion_function_preferred(model, y)

# process minibatches and perform evaluation
progress_printer = C.logging.ProgressPrinter(tag='Evaluation', num_epochs=0)

# Assign the data fields to be read from the input
else:

while True:
minibatch_size = 500
data = reader.next_minibatch(minibatch_size, input_map= data_map)  # fetch minibatch
if not data:                                 # until we hit the end
break

evaluator = C.eval.Evaluator(loss, progress_printer)
evaluator.test_minibatch(data)

evaluator.summarize_test_progress()

Now we can measure the model accuracy by going through all the examples in the test set and using the C.eval.Evaluator method.

In [13]:

def do_test():
do_test()
z.classify.b.value

Finished Evaluation [1]: Minibatch[1-23]: metric = 0.34% * 10984;

Out[13]:

array([ -1.86572317e-02,  -8.51036515e-03,   1.38878925e-02,
-1.95176266e-02,  -2.78977025e-03,  -1.23168388e-02,
-6.16775267e-03,  -1.48158008e-02,  -5.82036236e-03,
-2.99133137e-02,  -1.39552690e-02,  -2.11144108e-02,
-1.13499342e-02,  -1.25011550e-02,  -8.19404377e-04,
-5.26463473e-03,  -2.67275460e-02,  -1.80706571e-04,
-3.97865893e-03,  -2.99989916e-02,  -1.00385472e-02,
-6.81575621e-03,  -2.65348833e-02,  -2.01367699e-02,
-2.63106022e-02,   4.22888156e-03,   5.74267423e-03,
-1.56373512e-02,   7.71288527e-04,  -2.11508083e-03,
-9.64712165e-03,  -1.98591035e-02,  -1.32136559e-02,
7.97899254e-03,  -1.76088810e-02,   9.19441786e-03,
1.30802142e-02,  -3.85359419e-03,   1.86733739e-03,
-5.96518070e-03,  -3.07163727e-02,  -3.04672867e-03,
-3.46868881e-04,  -1.29565294e-03,  -4.47260169e-03,
-1.29292896e-02,  -1.05356863e-02,  -9.16024856e-03,
6.08767197e-03,  -3.75504000e-03,  -2.08706614e-02,
-6.74075307e-03,  -1.62283499e-02,  -1.54837407e-02,
-4.45737224e-03,  -2.18946021e-02,  -7.09120464e-03,
-2.59322841e-02,  -7.19473930e-03,  -2.38050371e-02,
-2.12035086e-02,  -1.92295481e-02,  -1.78258196e-02,
-2.89904419e-02,  -2.11317427e-02,  -1.59252994e-02,
1.15247713e-02,  -6.23733690e-03,  -2.34362725e-02,
-2.94410121e-02,  -2.90733539e-02,  -2.31353957e-02,
-2.56022997e-02,  -2.99183521e-02,  -3.48845944e-02,
-2.37278938e-02,  -1.23830158e-02,  -8.28807056e-03,
-7.39323627e-03,  -2.71228235e-02,  -1.66217834e-02,
-2.01343931e-02,  -7.25648087e-03,  -1.39272353e-02,
-6.12456305e-03,  -1.73326526e-02,  -2.00424399e-02,
-6.42115856e-03,  -1.77380182e-02,   2.44801558e-05,
-2.94576529e-02,   3.32167302e-03,  -2.08815038e-02,
-1.13182077e-02,  -1.59333460e-02,  -1.49212936e-02,
5.97879477e-03,  -1.84684750e-02,  -2.37341877e-02,
-3.12264990e-02,   5.03906514e-03,  -3.30699719e-02,
-2.31159870e-02,  -9.83368699e-03,  -2.43863855e-02,
-1.25425290e-02,  -2.47525666e-02,  -9.63981543e-03,
-1.55018885e-02,  -9.93501674e-03,  -1.19379470e-02,
-5.87523589e-03,  -1.70155372e-02,  -2.29082517e-02,
-1.84413474e-02,  -1.43948747e-02,  -1.95573717e-02,
-1.57539565e-02,  -1.90414693e-02,  -9.15751979e-03,
-2.89104711e-02,  -1.02876564e-02,  -2.83453409e-02,
-1.30684981e-02,  -5.12228906e-03,  -1.68853626e-02,
-1.10401753e-02,  -7.05094775e-03,   1.51731307e-02], dtype=float32)

The following block of code illustrates how to evaluate a single sequence. Additionally we show how one can pass in the information using NumPy arrays.

In [14]:

# load dictionaries
query_wl = [line.rstrip('\n') for line in open(data['query']['file'])]
slots_wl = [line.rstrip('\n') for line in open(data['slots']['file'])]
query_dict = {query_wl[i]:i for i in range(len(query_wl))}
slots_dict = {slots_wl[i]:i for i in range(len(slots_wl))}

# let's run a sequence through
seq = 'BOS flights from new york to seattle EOS'
w = [query_dict[w] for w in seq.split()] # convert to word indices
print(w)
onehot = np.zeros([len(w),len(query_dict)], np.float32)
for t in range(len(w)):
onehot[t,w[t]] = 1

#x = C.sequence.input_variable(vocab_size)
pred = z(x).eval({x:[onehot]})[0]
print(pred.shape)
best = np.argmax(pred,axis=1)
print(best)
list(zip(seq.split(),[slots_wl[s] for s in best]))

[178, 429, 444, 619, 937, 851, 752, 179]
(8, 129)
[128 128 128  48 110 128  78 128]

Out[14]:

[('BOS', 'O'),
('flights', 'O'),
('from', 'O'),
('new', 'B-fromloc.city_name'),
('york', 'I-fromloc.city_name'),
('to', 'O'),
('seattle', 'B-toloc.city_name'),
('EOS', 'O')]

## Modifying the Model¶

In the following, you will be given tasks to practice modifying CNTK configurations. The solutions are given at the end of this document... but please try without!

A Word About Sequential() <https://www.cntk.ai/pythondocs/layerref.html#sequential>__

Before jumping to the tasks, let’s have a look again at the model we just ran. The model is described in what we call function-composition style.

Sequential([
Embedding(emb_dim),
Recurrence(LSTM(hidden_dim), go_backwards=False),
Dense(num_labels)
])

You may be familiar with the “sequential” notation from other neural-network toolkits. If not, Sequential() <https://www.cntk.ai/pythondocs/layerref.html#sequential>__ is a powerful operation that, in a nutshell, allows to compactly express a very common situation in neural networks where an input is processed by propagating it through a progression of layers. Sequential() takes an list of functions as its argument, and returns a new function that invokes these functions in order, each time passing the output of one to the next. For example,

FGH = Sequential ([F,G,H])
y = FGH (x)

means the same as

y = H(G(F(x)))

This is known as “function composition”, and is especially convenient for expressing neural networks, which often have this form:

     +-------+   +-------+   +-------+
x -->|   F   |-->|   G   |-->|   H   |--> y
+-------+   +-------+   +-------+

Coming back to our model at hand, the Sequential expression simply says that our model has this form:

     +-----------+   +----------------+   +------------+
x -->| Embedding |-->| Recurrent LSTM |-->| DenseLayer |--> y
+-----------+   +----------------+   +------------+

We now want to add new layers to the model, specifically batch normalization.

Batch normalization is a popular technique for speeding up convergence. It is often used for image-processing setups. But could it work for recurrent models, too?

Note: training with Batch Normalization is currently only supported on GPU.

So your task will be to insert batch-normalization layers before and after the recurrent LSTM layer. If you have completed the hands-on labs on image processing, you may remember that the batch-normalization layer has this form:

BatchNormalization()

So please go ahead and modify the configuration and see what happens.

If everything went right, you will notice improved convergence speed (loss and metric) compared to the previous configuration.

In [15]:

# Your task: Add batch normalization
def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim),
C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_labels)
])

# Enable these when done:
#do_train()
#do_test()

Our recurrent model suffers from a structural deficit: Since the recurrence runs from left to right, the decision for a slot label has no information about upcoming words. The model is a bit lopsided. Your task will be to modify the model such that the input to the recurrence consists not only of the current word, but also of the next one (lookahead).

Your solution should be in function-composition style. Hence, you will need to write a Python function that does the following:

• takes no input arguments
• creates a placeholder (sequence) variable
• computes the “next value” in this sequence using the sequence.future_value() operation and
• concatenates the current and the next value into a vector of twice the embedding dimension using splice()

and then insert this function into Sequential()‘s list right after the embedding layer.

In [16]:

# Your task: Add lookahead
def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim),
C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_labels)
])

# Enable these when done:
#do_train()
#do_test()

### Task 3: Bidirectional Recurrent Model¶

Aha, knowledge of future words help. So instead of a one-word lookahead, why not look ahead until all the way to the end of the sentence, through a backward recurrence? Let us create a bidirectional model!

Your task is to implement a new layer that performs both a forward and a backward recursion over the data, and concatenates the output vectors.

Note, however, that this differs from the previous task in that the bidirectional layer contains learnable model parameters. In function-composition style, the pattern to implement a layer with model parameters is to write a factory function that creates a function object.

A function object, also known as *functor*, is an object that is both a function and an object. Which means nothing else that it contains data yet still can be invoked as if it was a function.

For example, Dense(outDim) is a factory function that returns a function object that contains a weight matrix W, a bias b, and another function to compute input @ W + b. (This is using Python 3.5 notation for matrix multiplication. In Numpy syntax it is input.dot(W) + b). E.g. saying Dense(1024) will create this function object, which can then be used like any other function, also immediately: Dense(1024)(x).

Let’s look at an example for further clarity: Let us implement a new layer that combines a linear layer with a subsequent batch normalization. To allow function composition, the layer needs to be realized as a factory function, which could look like this:

def DenseLayerWithBN(dim):
F = Dense(dim)
G = BatchNormalization()
x = placeholder()
apply_x = G(F(x))
return apply_x

Invoking this factory function will create F, G, x, and apply_x. In this example, F and G are function objects themselves, and apply_x is the function to be applied to the data. Thus, e.g. calling DenseLayerWithBN(1024) will create an object containing a linear-layer function object called F, a batch-normalization function object G, and apply_x which is the function that implements the actual operation of this layer using F and G. It will then return apply_x. To the outside, apply_x looks and behaves like a function. Under the hood, however, apply_x retains access to its specific instances of F and G.

Now back to our task at hand. You will now need to create a factory function, very much like the example above. You shall create a factory function that creates two recurrent layer instances (one forward, one backward), and then defines an apply_x function which applies both layer instances to the same x and concatenate the two results.

Alright, give it a try! To know how to realize a backward recursion in CNTK, please take a hint from how the forward recursion is done. Please also do the following: * remove the one-word lookahead you added in the previous task, which we aim to replace; and * make sure each LSTM is using hidden_dim//2 outputs to keep the total number of model parameters limited.

In [17]:

# Your task: Add bidirectional recurrence
def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim),
C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_labels)
])

# Enable these when done:
#do_train()
#do_test()

The bidirectional model has 40% less parameters than the lookahead one. However, if you go back and look closely you may find that the lookahead one trained about 30% faster. This is because the lookahead model has both less horizontal dependencies (one instead of two recurrences) and larger matrix products, and can thus achieve higher parallelism.

In [18]:

def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim),
#C.layers.BatchNormalization(), #Remove this comment if running on GPU
C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False),
#C.layers.BatchNormalization(), #Remove this comment if running on GPU
C.layers.Dense(num_labels)
])

do_train()
do_test()

Training 721479 parameters in 6 parameter tensors.
Learning rate per minibatch: 0.020999999999999998
Finished Epoch[1 of 10]: [Training] loss = 1.740198 * 18010, metric = 28.02% * 18010 4.223s (4264.7 samples/s);
Finished Epoch[2 of 10]: [Training] loss = 0.665177 * 18051, metric = 14.30% * 18051 3.917s (4608.4 samples/s);
Finished Epoch[3 of 10]: [Training] loss = 0.526256 * 17941, metric = 11.34% * 17941 3.898s (4602.6 samples/s);
Finished Epoch[4 of 10]: [Training] loss = 0.395405 * 18059, metric = 8.22% * 18059 4.061s (4446.9 samples/s);
Learning rate per minibatch: 0.010499999999999999
Finished Epoch[5 of 10]: [Training] loss = 0.293512 * 17957, metric = 6.20% * 17957 3.996s (4493.7 samples/s);
Finished Epoch[6 of 10]: [Training] loss = 0.264932 * 18021, metric = 5.73% * 18021 3.931s (4584.3 samples/s);
Finished Epoch[7 of 10]: [Training] loss = 0.217258 * 17980, metric = 4.69% * 17980 3.941s (4562.3 samples/s);
Finished Epoch[8 of 10]: [Training] loss = 0.209614 * 18025, metric = 4.55% * 18025 4.105s (4391.0 samples/s);
Finished Epoch[9 of 10]: [Training] loss = 0.165851 * 17956, metric = 3.84% * 17956 3.963s (4530.9 samples/s);
Finished Epoch[10 of 10]: [Training] loss = 0.157653 * 18039, metric = 3.41% * 18039 4.051s (4453.0 samples/s);
Finished Evaluation [1]: Minibatch[1-23]: metric = 0.34% * 10984;

In [19]:

def OneWordLookahead():
x = C.placeholder()
apply_x = C.splice(x, C.sequence.future_value(x))
return apply_x

def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim),
C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_labels)
])

do_train()
do_test()

Training 901479 parameters in 6 parameter tensors.
Learning rate per minibatch: 0.020999999999999998
Finished Epoch[1 of 10]: [Training] loss = 1.618925 * 18010, metric = 26.40% * 18010 4.567s (3943.5 samples/s);
Finished Epoch[2 of 10]: [Training] loss = 0.572762 * 18051, metric = 12.46% * 18051 5.560s (3246.6 samples/s);
Finished Epoch[3 of 10]: [Training] loss = 0.420728 * 17941, metric = 8.57% * 17941 5.254s (3414.7 samples/s);
Finished Epoch[4 of 10]: [Training] loss = 0.297996 * 18059, metric = 6.28% * 18059 5.697s (3169.9 samples/s);
Learning rate per minibatch: 0.010499999999999999
Finished Epoch[5 of 10]: [Training] loss = 0.224015 * 17957, metric = 4.81% * 17957 5.612s (3199.8 samples/s);
Finished Epoch[6 of 10]: [Training] loss = 0.207126 * 18021, metric = 4.61% * 18021 5.487s (3284.3 samples/s);
Finished Epoch[7 of 10]: [Training] loss = 0.170268 * 17980, metric = 3.69% * 17980 5.538s (3246.7 samples/s);
Finished Epoch[8 of 10]: [Training] loss = 0.164910 * 18025, metric = 3.65% * 18025 5.467s (3297.1 samples/s);
Finished Epoch[9 of 10]: [Training] loss = 0.126314 * 17956, metric = 2.92% * 17956 4.340s (4137.3 samples/s);
Finished Epoch[10 of 10]: [Training] loss = 0.122896 * 18039, metric = 2.67% * 18039 4.218s (4276.7 samples/s);
Finished Evaluation [1]: Minibatch[1-23]: metric = 0.38% * 10984;

Solution 3: Bidirectional Recurrent Model

In [20]:

def BiRecurrence(fwd, bwd):
F = C.layers.Recurrence(fwd)
G = C.layers.Recurrence(bwd, go_backwards=True)
x = C.placeholder()
apply_x = C.splice(F(x), G(x))
return apply_x

def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim),
BiRecurrence(C.layers.LSTM(hidden_dim//2),
C.layers.LSTM(hidden_dim//2)),
C.layers.Dense(num_labels)
])

do_train()
do_test()

Training 541479 parameters in 9 parameter tensors.
Learning rate per minibatch: 0.020999999999999998
Finished Epoch[1 of 10]: [Training] loss = 1.886776 * 18010, metric = 30.06% * 18010 7.619s (2363.8 samples/s);
Finished Epoch[2 of 10]: [Training] loss = 0.683211 * 18051, metric = 14.83% * 18051 7.325s (2464.3 samples/s);
Finished Epoch[3 of 10]: [Training] loss = 0.521379 * 17941, metric = 11.42% * 17941 7.265s (2469.5 samples/s);
Finished Epoch[4 of 10]: [Training] loss = 0.394698 * 18059, metric = 8.11% * 18059 7.567s (2386.5 samples/s);
Learning rate per minibatch: 0.010499999999999999
Finished Epoch[5 of 10]: [Training] loss = 0.288926 * 17957, metric = 6.06% * 17957 7.386s (2431.2 samples/s);
Finished Epoch[6 of 10]: [Training] loss = 0.267000 * 18021, metric = 5.73% * 18021 7.401s (2434.9 samples/s);
Finished Epoch[7 of 10]: [Training] loss = 0.215379 * 17980, metric = 4.69% * 17980 7.269s (2473.5 samples/s);
Finished Epoch[8 of 10]: [Training] loss = 0.206970 * 18025, metric = 4.37% * 18025 7.333s (2458.1 samples/s);
Finished Epoch[9 of 10]: [Training] loss = 0.160564 * 17956, metric = 3.39% * 17956 7.196s (2495.3 samples/s);
Finished Epoch[10 of 10]: [Training] loss = 0.154584 * 18039, metric = 3.20% * 18039 7.337s (2458.6 samples/s);
Finished Evaluation [1]: Minibatch[1-23]: metric = 0.38% * 10984;

We will reuse the same data for this task. We revisit a sample again:

19  |S0 178:1 |# BOS      |S1 14:1 |# flight  |S2 128:1 |# O
19  |S0 770:1 |# show                         |S2 128:1 |# O
19  |S0 429:1 |# flights                      |S2 128:1 |# O
19  |S0 444:1 |# from                         |S2 128:1 |# O
19  |S0 272:1 |# burbank                      |S2 48:1  |# B-fromloc.city_name
19  |S0 851:1 |# to                           |S2 128:1 |# O
19  |S0 789:1 |# st.                          |S2 78:1  |# B-toloc.city_name
19  |S0 564:1 |# louis                        |S2 125:1 |# I-toloc.city_name
19  |S0 654:1 |# on                           |S2 128:1 |# O
19  |S0 601:1 |# monday                       |S2 26:1  |# B-depart_date.day_name
19  |S0 179:1 |# EOS                          |S2 128:1 |# O

The task of the neural network is to look at the query (column S0) and predict the intent of the sequence (column S1). We will ignore the slot-tags (column S2) this time.

### Model Creation¶

The model we will use is a recurrent model consisting of an embedding layer, a recurrent LSTM cell, and a dense layer to compute the posterior probabilities. Though very similar to the slot tagging model in this case we look only at the embedding from the last layer:

intent                                                "flight"
^
|
+-------+
| Dense |   ...
+-------+
^
|
+------+   +------+   +------+   +------+   +------+
0 -->| LSTM |-->| LSTM |-->| LSTM |-->| LSTM |-->| LSTM |-->...
+------+   +------+   +------+   +------+   +------+
^          ^          ^          ^          ^
|          |          |          |          |
+-------+  +-------+  +-------+  +-------+  +-------+
| Embed |  | Embed |  | Embed |  | Embed |  | Embed |  ...
+-------+  +-------+  +-------+  +-------+  +-------+
^          ^          ^          ^          ^
|          |          |          |          |
w      ------>+--------->+--------->+--------->+--------->+------...
BOS      "show"    "flights"    "from"   "burbank"

Or, as a CNTK network description. Please have a quick look and match it with the description above: (descriptions of these functions can be found at: the layers reference)

#### Points to note:¶

• The first difference between this model with the previous one is with regards to the specification of the label y. Since there is only one label per sequence, we use C.input_variable.
• The second difference is the use of Stabilizer. We stabilize the embedded output. The stabilizer adds an additional scalar parameter to the learning that can help our network converge more quickly during training.
• The third difference is the use of a layer function called Fold. As shown in the model above we want the model to have LSTM recurrence except the final one, we set up an LSTM recurrence. The final recurrence will be a Fold operation where we pick the hidden state from the last LSTM block and use it for classification of the entire sequence.
In [21]:

# number of words in vocab, slot labels, and intent labels
vocab_size = 943 ; num_intents = 26

# model dimensions
emb_dim    = 150
hidden_dim = 300

# Create the containers for input feature (x) and the label (y)
x = C.sequence.input_variable(vocab_size)
y = C.input_variable(num_intents)

def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim, name='embed'),
C.layers.Stabilizer(),
C.layers.Fold(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_intents, name='classify')
])

We create the criterion function with the new model and correspondingly update the placeholder.

In [22]:

criterion = create_criterion_function(create_model())
criterion.replace_placeholders({criterion.placeholders[0]: C.sequence.input_variable(num_intents)})

Out[22]:

Composite(Combine): Input('Input14623', [#, *], [26]), Placeholder('labels', [???], [???]) -> Output('Block14593_Output_0', [#], [1]), Output('Block14613_Output_0', [#], [])

The same train code can be used except for the fact that in this case we provide the intent tags as the labels.

In [23]:

def do_train():
global z
z = create_model()
do_train()

Training 690477 parameters in 7 parameter tensors.
Learning rate per minibatch: 0.020999999999999998
Finished Epoch[1 of 5]: [Training] loss = 0.585308 * 18004, metric = 14.42% * 18004 79.421s (226.7 samples/s);
Finished Epoch[2 of 5]: [Training] loss = 0.153843 * 17998, metric = 3.92% * 17998 74.394s (241.9 samples/s);
Finished Epoch[3 of 5]: [Training] loss = 0.081964 * 18000, metric = 2.17% * 18000 59.060s (304.8 samples/s);
Finished Epoch[4 of 5]: [Training] loss = 0.069163 * 18000, metric = 1.92% * 18000 58.621s (307.1 samples/s);
Learning rate per minibatch: 0.010499999999999999
Finished Epoch[5 of 5]: [Training] loss = 0.018180 * 17998, metric = 0.47% * 17998 58.345s (308.5 samples/s);

Now we can measure the model accuracy by going through all the examples in the test set and using the C.eval.Evaluator method.

In [24]:

def do_test():
do_test()
z.classify.b.value

Finished Evaluation [1]: Minibatch[1-23]: metric = 0.00% * 893;

Out[24]:

array([ 0.51183742, -0.29180217, -0.41856512, -0.28958377, -0.72160971,
-0.24883319,  0.02916328, -0.0852626 ,  0.19014142, -0.41936243,
-0.23639332, -0.29029393, -0.74258387, -0.12296562,  0.34665295,
-0.46388549, -0.73981428, -0.2296015 , -0.78151304, -0.24418215,
-0.52702737,  0.10101102, -0.27433836, -0.24181543, -0.39551306,
0.30569023], dtype=float32)

The following block of code illustrates how to evaluate a single sequence. Additionally, we show how one can pass in the information using NumPy arrays.

In [25]:

# load dictionaries
query_wl = [line.rstrip('\n') for line in open(data['query']['file'])]
intent_wl = [line.rstrip('\n') for line in open(data['intent']['file'])]
query_dict = {query_wl[i]:i for i in range(len(query_wl))}
intent_dict = {intent_wl[i]:i for i in range(len(intent_wl))}

# let's run a sequence through
seq = 'BOS flights from new york to seattle EOS'
w = [query_dict[w] for w in seq.split()] # convert to word indices
onehot = np.zeros([len(w),len(query_dict)], np.float32)
for t in range(len(w)):
onehot[t,w[t]] = 1

pred = z(x).eval({x:[onehot]})[0]
best = np.argmax(pred)
print(best)
print(seq, ":", intent_wl[best])

14
BOS flights from new york to seattle EOS : flight

Task 4: Use all hidden states for sequence classification

In the last model, we looked at the output of the last LSTM block. There is another way to model, where we aggregate the output from all the LSTM blocks and use the aggregated output to the final Dense layer.

So your task will be to replace the C.layers.Fold with C.layers.Recurrence layer function. This is the explicit way of setting up recurrence. You will aggregate all the intermediate outputs from LSTM blocks using C.sequence.reduce_sum. Note: this is different from last model where we looked only at the output of the last LSTM block.

So please go ahead and modify the configuration and see what happens.

If everything went right, you will notice improved accuracy (metric). The solution is presented right after, but we suggest you refrain from looking at the solution.

In [26]:

# Replace the line with Fold operation
def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim, name='embed'),
C.layers.Stabilizer(),
C.layers.Fold(C.layers.LSTM(hidden_dim), go_backwards=False),
C.layers.Dense(num_intents, name='classify')
])
# Enable these when done:
#do_train()
#do_test()

Aggregating all the intermediate states improves the accuracy for the same number of iterations without any significant increase in the computation time.

Solution 4: Use all hidden states for sequence classification

In [27]:

def create_model():
with C.layers.default_options(initial_state=0.1):
return C.layers.Sequential([
C.layers.Embedding(emb_dim, name='embed'),
C.layers.Stabilizer(),
C.sequence.reduce_sum(C.layers.Recurrence(C.layers.LSTM(hidden_dim), go_backwards=False)),
C.layers.Dense(num_intents, name='classify')
])

do_train()
do_test()

Training 690477 parameters in 7 parameter tensors.
Learning rate per minibatch: 0.020999999999999998
Finished Epoch[1 of 5]: [Training] loss = 0.193482 * 18004, metric = 4.07% * 18004 56.904s (316.4 samples/s);
Finished Epoch[2 of 5]: [Training] loss = 0.028983 * 17998, metric = 0.64% * 17998 73.820s (243.8 samples/s);
Finished Epoch[3 of 5]: [Training] loss = 0.059269 * 18000, metric = 1.24% * 18000 71.494s (251.8 samples/s);
Finished Epoch[4 of 5]: [Training] loss = 0.005993 * 18000, metric = 0.18% * 18000 61.856s (291.0 samples/s);
Learning rate per minibatch: 0.010499999999999999
Finished Epoch[5 of 5]: [Training] loss = 0.000344 * 17998, metric = 0.01% * 17998 57.114s (315.1 samples/s);
Finished Evaluation [1]: Minibatch[1-23]: metric = 0.00% * 893;


text:
Which authority regulates airliner design?

To which regulating authority's regulations and standards are large sub-sonic transport aircraft (passenger or cargo) designed? The FAA's, or EASA's, or both?

The safe operations of an aircraft is called airworthiness. It is the standard by which an aircraft is determined fit to fly. Responsibility of airworthiness lies with national aviation regulatory bodies, manufacturers, as well as owners and operators. International standards are dictated by ICAO during the aircraft design process:

The International Civil Aviation Organization sets international standards and recommended practices for national authorities to base their regulations on

FAA has regulations governing all aviation activities in the US. EASA also has airworthiness regulations.

The aircraft manufacturer makes sure that the aircraft meets existing design standards, defines the operating limitations and maintenance schedules and provides support and maintenance throughout the operational life of the aircraft.

• Thank you for the answer. Your link to 'regulations' take me to a regulation that governs maintenance for aircraft below 5700 kg used for non-commercial uses. Does this mean that larger aircraft are not governed by airworthiness regulations from EASA, but rather by ICAO recommended practices? It seems you are placing an emphasis on a difference between 'rules' and 'regulations', is this an accurate assessment? Dec 1, 2014 at 16:49
• Good catch. I didn't realize that the Wikipedia article had some missing/confusing information. A quick search about EASA's regulations for airworthiness didn't return anything useful. I will try to find some more information and will update my answer.
– Farhan
Dec 1, 2014 at 17:17
• @Jonny Not quite. ICAO sets general standards, but does not set regulations or issue type certificates; that's done by national(-ish, for the EU) regulators. ICAO recommendations are to national authorities, but the national authorities actually set the rules. The type certificate is issued by the authority where the manufacturer is based (in general, aviation authorities accept each other's type certificates). Dec 1, 2014 at 18:57
• @cpast: Indeed. However the individual authorities usually follow the ICAO recommendations quite closely. FAA probably differs most often. Dec 2, 2014 at 19:18

In the USA, the FAA regulates airworthiness. For transport category aircraft, such as Boeing and Airbus, the regulations are in 14 CFR Part 25.

• Thanks. Do you know what the EASA regulation is that governs transport category? Dec 1, 2014 at 19:38
• No, sorry I don't
– rbp
Dec 1, 2014 at 19:40
• I think it is CS-25 Amendment 10 Dec 1, 2014 at 19:44


text:
Summer is Coming! Join the Game of Timers Competition to Win Epic Prizes. Registration is Open. Game starts Mon July 1st.

 It is currently 17 Jul 2019, 14:05

GMAT Club Daily Prep

Thank you for using the timer - this advanced tool can estimate your performance and suggest more practice questions. We have subscribed you to Daily Prep Questions via email.

Customized
for You

we will pick new questions that match your level based on your Timer History

Track

every week, we’ll send you an estimated GMAT score based on your performance

Practice
Pays

we will pick new questions that match your level based on your Timer History

If x is a prime number, what is the value of x + c?

 new topic post reply Question banks Downloads My Bookmarks Reviews Important topics
Author Message
TAGS:

Hide Tags

Math Expert
Joined: 02 Sep 2009
Posts: 56277
If x is a prime number, what is the value of x + c?  [#permalink]

Show Tags

19 Dec 2018, 01:45
11
00:00

Difficulty:

95% (hard)

Question Stats:

29% (02:08) correct 71% (02:20) wrong based on 143 sessions

HideShow timer Statistics

FRESH GMAT CLUB CHALLENGE PROBLEM

If x is a prime number, what is the value of x + c?

(1) $$|a + b + c - 2x| + \sqrt{(x^2 - a - b - c)^2} = - |c|$$

(2) $$\sqrt{(a + b + c - 1 + x)^2} + |\frac{1}{1-x}- a - b - c| + \sqrt{c^2}=0$$

_________________
Math Expert
Joined: 02 Aug 2009
Posts: 7764
Re: If x is a prime number, what is the value of x + c?  [#permalink]

Show Tags

19 Dec 2018, 09:27
6
4
If x is a prime number, what is the value of x + c?

(1) $$|a + b + c - 2x| + \sqrt{(x^2 - a - b - c)^2} = - |c|$$
The RHS - |c| can only be possible as 0, because the LHS has SUM of a modulus and a square root, both of which are positive. so it will be positive and -|c| cannot be positive
Now, the LHS, $$|a + b + c - 2x| + \sqrt{(x^2 - a - b - c)^2} =0$$ , but since both terms are positive, they should be 0 themselves too..
so a + b + c - 2x=0......a+b+c=2x...(i)
Also $$\sqrt{(x^2 - a - b - c)^2} =0......=>x^2 - a - b - c=0.........x^2=a+b+c$$...(ii)
From (i) and (ii), we get $$a+b+c=2x=x^2........x^2-x=0....x(x-2)=0$$, so x is 0 or 2
But x is a prime number, so x+c=2+0=2
sufficient

(2) $$\sqrt{(a + b + c - 1 + x)^2} + |\frac{1}{x-1}- a - b - c| + \sqrt{c^2}=0$$
All terms on LHS are positive, so their SUM can only be 0 when all terms are 0..
$$\sqrt{c^2}=0, so c=0.$$
$$|\frac{1}{x-1}- a - b - c|=0..............|\frac{1}{x-1}= a + b|$$...(i)
$$\sqrt{(a + b + c - x+1)^2}=0.........a + b + c - x+1 =0..........a+b=x-1.$$...(ii)
from (i) and (ii).. $$\frac{1}{x-1}= a + b=x-1........x-1=\frac{1}{x-1}......(x-1)^2=1$$, so x can be 0 or 2
But x is prime number so 2
hence x+c=2+0=2
suff

D

Note:- Bunuel, there seems to be a typo in statement II.
Either it is 1/(1-x) and not 1/(x-1) or it is a+b+c-x+1 and not a+b+c-1+x...
Pl relook
_________________
General Discussion
Intern
Joined: 21 Aug 2018
Posts: 4
Re: If x is a prime number, what is the value of x + c?  [#permalink]

Show Tags

20 Dec 2018, 22:39
1
chetan2u

Hi sir,

Isn't statement 2: a + b + c -1 + x = 0 => a + b = 1-x ?
if that holds true, we have: 1/ (x-1) = 1-x => no solution for the equation?

Thanks!
Math Expert
Joined: 02 Aug 2009
Posts: 7764
Re: If x is a prime number, what is the value of x + c?  [#permalink]

Show Tags

21 Dec 2018, 06:26
1
Lincoln1608 wrote:
chetan2u

Hi sir,

Isn't statement 2: a + b + c -1 + x = 0 => a + b = 1-x ?
if that holds true, we have: 1/ (x-1) = 1-x => no solution for the equation?

Thanks!

Hi..

You are correct in your observation. I too saw it and I took it as typo and answered accordingly. May be I'll request Bunuel to relook into it.
_________________
Math Expert
Joined: 02 Sep 2009
Posts: 56277
Re: If x is a prime number, what is the value of x + c?  [#permalink]

Show Tags

21 Dec 2018, 06:36
chetan2u wrote:
Lincoln1608 wrote:
chetan2u

Hi sir,

Isn't statement 2: a + b + c -1 + x = 0 => a + b = 1-x ?
if that holds true, we have: 1/ (x-1) = 1-x => no solution for the equation?

Thanks!

Hi..

You are correct in your observation. I too saw it and I took it as typo and answered accordingly. May be I'll request Bunuel to relook into it.

Yes. Kudos to you for solving correctly very hard question even with a typo in it.
_________________
Math Expert
Joined: 02 Sep 2009
Posts: 56277
Re: If x is a prime number, what is the value of x + c?  [#permalink]

Show Tags

24 Dec 2018, 01:16
Bunuel wrote:

FRESH GMAT CLUB CHALLENGE PROBLEM

If x is a prime number, what is the value of x + c?

(1) $$|a + b + c - 2x| + \sqrt{(x^2 - a - b - c)^2} = - |c|$$

(2) $$\sqrt{(a + b + c - 1 + x)^2} + |\frac{1}{1-x}- a - b - c| + \sqrt{c^2}=0$$

_________________
Re: If x is a prime number, what is the value of x + c?   [#permalink] 24 Dec 2018, 01:16
Display posts from previous: Sort by

If x is a prime number, what is the value of x + c?

 new topic post reply Question banks Downloads My Bookmarks Reviews Important topics

 Powered by phpBB © phpBB Group | Emoji artwork provided by EmojiOne


text:
## Loren on the Art of MATLABTurn ideas into MATLAB

If you are a regular reader of the MATLAB Usenet newsgroup, comp.soft-sys.matlab, found on the MathWorks User Community page, you are probably familiar with repeated advice to not use the MATLAB function eval . Today I plan to tell you more about why this is generally good advice.

Statements containing a call to eval have a way of obscuring the underlying intent of the code though this is rarely a goal of the author. What do I mean by this? Well, in under 3 seconds, can you discern what the following code means?

a = who ;
a = a(~cellfun('isempty',regexp(a,'2\$'))) ;
str = sprintf('%s,',a{:}) ;
str = sprintf('B = cat(1,%s) ;',str(1:end-1)) ;
eval(str) ;

Unless you are one of the proponents of this code pattern (see this newsgroup post, for example), you likely couldn't tell that the code is saying

Concatenate all variables that have '_2' in their name, i.e. a_2, b_2, c_2

### Efficiency

When a function M-file is run in MATLAB for the first time in a session, MATLAB reads in the file, translates it into an internal representation, analyzes the contents, and executes the code. The next time you use this function in the same MATLAB session, assuming the file hasn't changed, MATLAB doesn't need to reread and translate the file.

However, if the M-file contains any calls to the function eval, at least those lines of code will need to be reinterpreted each time the function is run. Why? Because there is no guarantee, and it is generally not true, that the expression that was executed in the first instance is the same as subsequent ones. The expression may require different MATLAB functions or variables. In any case, to be sure MATLAB gets the right answer, at least the lines of code containing eval statements need to be re-analyzed with each invocation.

### Analyzability

In an M-file, if the functions being called are coded into strings so they can be placed into eval statements, it is very difficult to build up a complete understanding of the functions and files that your M-file depends upon, especially in a static way. It might be possible, though probably difficult and perhaps error-prone, to scan through an M-file to see where strings are used in eval statements and to try to pull out the possible function and file names from these.