Perception import math import matplotlib.pyplot as plt import numpy as np 입력 : 입력: (x1, x2) 출력: a = x1 * w1 + x2 * w2 + b 계산 y = 1, a > 임계값= 0, a Example def step_function(x): if x > 0: return 1 else: return 0 > Execute x = np.arange(-3, 4) print('x = ', x) for x_i in x: print(step_function(x_i), end ='\t') > Result x = [-3 -2 -1 0 1 2 3] 0 0 0 0 1 1 1 > Numpy.exp()와 Math.exp() 비교 def step_funct..
Perceptron(퍼셉트론) 다수의 신호를 입력 받아서, 하나의 신호를 출력 - And Gate def and_gate(x1, x2): w1, w2 = 1.0, 1.0 # 가중치 bias = -1 y = x1 * w1 + x2 * w2 + bias if y > 0: return 1 else: return 0 - Or Gate def or_gate(x1, x2): w1, w2 = 1.0, 1.0 b = -0.5 y = x1 * w1 + x2 * w2 + b if y > 0: return 1 else: return 0 - Nand Gate def nand_gate(x1, x2): w1, w2 = 0.5, 0.5 # 가중치(weight) b = 0 # 편향(bias) y = x1 * w1 + x2 * w2 ..
Do ~ Whille문을 이용해 정수값의 부호 판별하기 import java.util.Scanner; Scanner stdIn = new Scanner(System.in); int retry; // 다시 한 번? // Do 문에 의해 반복되는 루프 바디 do { System.out.print("정수 값:"); int n = stdIn.nextInt(); if (n>0) System.out.println("이 값은 양수입니다."); else if (n == 0) System.out.println("이 값은 0입니다."); else System.out.println("이 값은 음수입니다."); System.out.print("다시 한 번? 1-Yes/ 0-No : "); retry = stdIn.nextIn..
두 정숫값 중 작은 값과 큰 값을 표시하는 프로그램 import java.util.Scanner; Scanner stdIn = new Scanner(System.in); System.out.print("정수 a:"); int a = stdIn.nextInt(); System.out.print("정수 b:"); int b = stdIn.nextInt(); if (a == b) System.out.println("두 값이 같습니다."); else { int min, max; if (a < b) { min = a; max = b; }else { min = b; max = a; } System.out.println("작은 값은 " + min + "입니다."); System.out.println("큰 값은 " +..