Designing a combinational circuit for a vending machine - circuit

I want to design a combinational circuit for a vending machine, that delivers 2 items, tea( 2$) and water(1$). The machine accepts up to 3 dollars.
# I draw the truth table with 3 inputs(dollars) and 2 outputs(tea & water).
d1 d2 d3 : t w
-----------------
0 0 0 : 0 0
0 0 1 : 0 1
0 1 0 : 0 1
0 1 1 : 1 0
1 0 0 : 0 1
1 0 1 : 1 0
1 1 0 : 1 0
1 1 1 : 1 1
Is there a better way to draw the truth table?

Your initial truth table does not represent the vending machine fully. Consider, for example, that a customer depositing $2 should be allowed to buy one tea or two waters. Consider also that the machine should be forgiving of over depositing for a given purchasing request.
Definitions:
Inputs
d1-d2: binary encoding of money deposited.
t: tea requested.
w1-w2: binary encoding of number of waters requested.
Outputs
A: Accept amount deposited and provide requested tea and water.
D1-D2: binary encoding of change to return to buyer.
Truth Table
The following truth table captures
multiple possible selections for a given deposit.
change to be given if selection is less expensive than money
deposited.
I N P U T S || O U T P U T S
Depos | Request || Accept | Change
d2 d1 | t w2 w1 || A | D2 D1
-----------------------------------
0 0 | 0 0 0 || 0 | 0 0
0 0 | 0 0 1 || 0 | 0 0
0 0 | 0 1 0 || 0 | 0 0
0 0 | 0 1 1 || 0 | 0 0
0 0 | 1 0 0 || 0 | 0 0
0 0 | 1 0 1 || 0 | 0 0
0 0 | 1 1 0 || 0 | 0 0
0 0 | 1 1 1 || 0 | 0 0
0 1 | 0 0 0 || 0 | 0 0
0 1 | 0 0 1 || 1 | 0 0
0 1 | 0 1 0 || 0 | 0 0
0 1 | 0 1 1 || 0 | 0 0
0 1 | 1 0 0 || 0 | 0 0
0 1 | 1 0 1 || 0 | 0 0
0 1 | 1 1 0 || 0 | 0 0
0 1 | 1 1 1 || 0 | 0 0
1 0 | 0 0 0 || 0 | 0 0
1 0 | 0 0 1 || 1 | 0 1
1 0 | 0 1 0 || 1 | 0 0
1 0 | 0 1 1 || 0 | 0 0
1 0 | 1 0 0 || 1 | 0 0
1 0 | 1 0 1 || 0 | 0 0
1 0 | 1 1 0 || 0 | 0 0
1 0 | 1 1 1 || 0 | 0 0
1 1 | 0 0 0 || 0 | 0 0
1 1 | 0 0 1 || 1 | 1 0
1 1 | 0 1 0 || 1 | 0 1
1 1 | 0 1 1 || 1 | 0 0
1 1 | 1 0 0 || 1 | 0 1
1 1 | 1 0 1 || 1 | 0 0
1 1 | 1 1 0 || 0 | 0 0
1 1 | 1 1 1 || 0 | 0 0

Related

Returning column header corresponding to matched value in separate sheet

Sheet 1
Name
Gender
w
0
e
1
r
2
t
4
y
6
u
2
i
NoMatch
q
1
w
1
e
1
r
2
Sheet 2 - Note sheet 2 has 2 "w" under Name column
Name
Male 1
Female 2
other 3
other 4
other 5
Donotknow 6
w
0
0
0
0
0
0
w
1
0
0
0
0
0
a
0
0
0
0
0
1
q
1
0
0
0
0
0
r
0
1
0
0
0
0
e
1
0
0
0
0
0
t
0
0
0
1
1
0
y
0
0
0
0
0
1
u
0
1
0
0
0
0
I am using this formula in Sheet 1 under Gender:
=IFERROR(FILTER({1,2,3,4,5,6},INDEX(Sheet2!$B$2:$G$10,MATCH(A2,Sheet2!$A$2:$A$10,0),0)=1),"NoMatch")
If you can live with the fact that a zero stands for 'No Match', then try:
Formula in B1:
=BYROW(A2:A12,LAMBDA(a,MIN(IF((D2:D10=a)*E2:J10,SEQUENCE(,6),""))))
If not, then change too:
=LET(X,BYROW(A2:A12,LAMBDA(a,MIN(IF((D2:D10=a)*E2:J10,SEQUENCE(,6),"")))),IF(X,X,"No Match"))

How to interpret SVM output in Weka?

I have a Support Vector model in Weka (SMO) and I want to extract knowledge from this output:
=== Classifier model (full training set) ===
SMO
Kernel used:
Puk kernel
Classifier for classes: Positive, Negative
BinarySMO
0.9349 * <0.364865 0 0 1 0 1 0 0 0 1 1 1 0 1 1 1 > * X]
+ 0.743 * <0.486486 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 > * X]
+ 0.8578 * <0.391892 0 0 1 0 1 1 1 0 1 0 1 0 1 1 1 > * X]
- 0.815 * <0.297297 1 0 1 0 1 0 0 0 1 0 1 0 1 1 0 > * X]
- 0.2347 * <0.391892 1 0 1 0 1 1 0 1 0 0 1 1 1 1 1 > * X]
+ 1.1502 * <0.527027 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 > * X]
+ 0.6922 * <0.554054 0 0 1 0 1 1 0 1 1 0 1 0 0 1 1 > * X]
.....
- 0.3291 * <0.594595 1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 > * X]
+ 0.9296 * <0.364865 0 0 1 1 1 0 1 0 1 0 0 0 1 0 1 > * X]
+ 0.6504 * <0.351351 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 > * X]
- 0.0333 * <0.27027 1 1 0 0 0 1 0 1 0 0 0 1 1 1 1 > * X]
+ 0.0085 * <0.513514 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 > * X]
+ 0.8176 * <0.72973 0 1 1 0 1 1 0 1 0 0 0 1 0 0 1 > * X]
- 0.4812 * <1 1 0 0 1 1 0 1 1 0 0 1 0 0 0 1 > * X]
- 0.3286 * <0.256757 1 0 0 1 0 1 0 0 0 0 1 1 1 1 1 > * X]
.........
- 0.1838 * <0.635135 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0 > * X]
- 0.0976 * <0.189189 1 1 0 1 1 1 0 0 1 1 1 1 0 1 1 > * X]
- 0.0036 * <0.364865 1 1 0 1 0 1 0 1 1 0 1 1 0 1 0 > * X]
- 0.0157 * <0.554054 0 1 0 1 0 1 0 1 1 0 1 1 1 1 1 > * X]
.........
- 0.0167 * <0.621622 0 1 1 0 0 0 1 1 0 1 1 1 0 0 0 > * X]
+ 0.2005 * <0.5 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 > * X]
- 0.589
Number of support vectors: 378
Number of kernel evaluations: 131997 (92.5% cached)
How can I interpret this output?
Thanks in advance
Have a look at SMO's toString() method to see how the output is constructed. Check out the Puk kernel itself (publication), to see how its calculations are done.
The textual output of classifiers is usually only for informative purposes (it is optional and has no impact on a classifier). People usually apply trained models directly to new data rather than trying to understand the output (especially with support vector machines).

Python: How do I assign string values to numeric data?

Running the four commands results in below output, from a dataframe called cancer.
$ print("\n target")
$ print(cancer.target)
$ print("\n target_names")
$ print(cancer.target_names)
target
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0
1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 1 1
1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0 0 1 0 0 1 1 0 1 1 0 1 1 1 1 0 1
1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 1 1 0 0 0 1 0
1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 1 1 0 1 0 0 0 0 1 1 0 0 1 1
1 0 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 1 1
1 1 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0
0 1 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1
1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 1
0 1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 0 1 1 0 1 0 1 0 0
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0 0 0 0 0 0 1]
target_names
['malignant' 'benign']
How would I be able to assign "malignant" to 0 and "benign" to 1, and vice versa?
You can map it by using a dictionary
target=[0,0,0,0,0,1,1,1,0,1,0,0,1]
d={0:'malignant',1:'benign'}
target=[d[t] for t in target]
print(target)
['malignant', 'malignant', 'malignant', 'malignant', 'malignant', 'benign', 'benign', 'benign', 'malignant', 'benign', 'malignant', 'malignant', 'benign']
What so you mean by assign?
Something like this?
for i in range(len(cancer)):
if target[i]==0:
target[i]=target_names[0]
elif target[i]==1:
target[i]=target_names[1]

J Language rank of power function

t=:1
test=: monad define
t=.y
t=. t, 0
)
testloop=: monad def'test^:y t'
testloop 1
1 0
testloop 2
1 0 0
testloop 10
1 0 0 0 0 0 0 0 0 0 0
In order to simplify this
(testloop 0),(testloop 1), (testloop 2), ...
110100100010000...
I tried
, testloop"0 (i.10)
but it gives
1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0...
It seems like I have a problem with a rank, I can't figure out which one to use.
I would be grateful if you could help me on this issue.
Thank you!
This is not so much a rank problem as the fact that the results are padded with zeros so that the row lengths match.
testloop 1
1 0
testloop 2
1 0 0
testloop"0 [ 1 2
1 0 0
1 0 0
testloop"0 [ 1 2 3
1 0 0 0
1 0 0 0
1 0 0 0
If I redefine your test and testloop to add a different appending digit, we can see how the padding is working.
test2 =: 3 : 0
​t=. y
​t=. t,2
​)
test2loop=: monad def'test2^:y t'
test2loop"0 [1
1 2
test2loop"0 [2
1 2 2
test2loop"0 [ 1 2 NB. 0 padded in first row
1 2 0
1 2 2
test2loop"0 [ 1 2 3 NB. 0's padded in first two rows
1 2 0 0
1 2 2 0
1 2 2 2
To get around the padding issue I will use each=: &.> so that the results are boxed before combining to avoid the padding.
testloop each 1 2 3
+---+-----+-------+
|1 0|1 0 0|1 0 0 0|
+---+-----+-------+
testloop each i. 10
+-+---+-----+-------+---------+-----------+-------------+---------------+-----------------+-------------------+
|1|1 0|1 0 0|1 0 0 0|1 0 0 0 0|1 0 0 0 0 0|1 0 0 0 0 0 0|1 0 0 0 0 0 0 0|1 0 0 0 0 0 0 0 0|1 0 0 0 0 0 0 0 0 0|
+-+---+-----+-------+---------+-----------+-------------+---------------+-----------------+-------------------+
using ; to unbox and ravel the results
; testloop each i. 10
1 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
To be honest I would be more inclined to use the fact that complex numbers used as the left argument of # introduce 0's for padding. The number of 0's depends on the imaginary value of the complex number.
1j0 # 1
1
1j1 # 1
1 0
1j2 # 1
1 0 0
test3=: monad def '(1 j. y)#1'
test3 1
1 0
test3 2
1 0 0
test3 1 2
1 0 1 0 0
test3 i. 10
1 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

How to find which combinations have the most frequency?

I have an SPSS data set with 500+ respondents and 18 symptoms that they could have.
Each symptom has its own variable Symptom01 = 1 means they have the symptom 1 Symptom02 = 0 means they dont have the symptom 2 etc etc
What I want to know is what combination of 3 symptoms is more frequent in my data set. For example how many people have symptom 1, 5 and 6; how many people have symptom 1, 2 and 3, etc.
I doesn't mean that they only have those symptoms. Theey could have others. I just want to know which group of 3 symptoms is more frequent in my dataset.
It's a lot of combinations so how would you do this?
Can someone help me?
Please note the macro below uses the variable names Symptom1, Symptom2 etc' instead of "Symptom01", "Symptom02"...
First creating some sample data to work on:
data list list/Symptom1 to Symptom18.
begin data
1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1
1 1 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 0
0 1 1 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0
1 0 0 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0
1 0 1 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0
0 0 0 1 1 1 0 0 0 0 1 0 0 0 1 0 0 1
1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 0 1
1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 0
0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 1 1 1
1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0
end data.
Now defining a macro with three loops:
EDIT - this version accounts for repeating combinations of symptoms
define AllCombsOf3 ()
!do !vr1=1 !to 18
!do !vr2=!vr1 !to 18
!do !vr3=!vr2 !to 18
!if (!vr2<>!vr1 !and !vr2<>!vr3) !then
compute !concat("C_",!vr1,"_",!vr2,"_",!vr3)= !concat("Symptom",!vr1)=1 & !concat("Symptom",!vr2)=1 & !concat("Symptom",!vr3)=1 .
!ifend
!doend
!doend
!doend
!enddefine.
Running the macro and displaying wanted results:
AllCombsOf3.
means C_1_2_3 to C_16_17_18.
EDIT 2 - new macro for a four symptom version
define AllCombsOf4 ()
!do !vr1=1 !to 18
!do !vr2=!vr1 !to 18
!do !vr3=!vr2 !to 18
!do !vr4=!vr3 !to 18
!if (!vr2<>!vr1 !and !vr2<>!vr3 !and !vr3<>!vr4) !then
compute !concat("C_",!vr1,"_",!vr2,"_",!vr3,"_",!vr4)=
!concat("Symptom",!vr1)=1 & !concat("Symptom",!vr2)=1 &
!concat("Symptom",!vr3)=1 & !concat("Symptom",!vr4)=1 .
!ifend
!doend !doend !doend !doend
!enddefine.
AllCombsOf4.
means C_1_2_3_4 to C_15_16_17_18.

Resources