Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- StochasticNum Neuron::think()
- {
- StochasticNum outputa(0, 500);
- StochasticNum outputb(0, 500);
- for (int i = 0; i < m_numweights; i++)
- {
- if (m_weight[i].getIsNegative())
- continue;
- StochasticNum n = m_weight[i] * m_input[i];
- outputa.add(n, *m_onehalf);
- }
- for (int i = 0; i < m_numweights; i++)
- {
- if (!m_weight[i].getIsNegative())
- continue;
- StochasticNum n = m_weight[i] * m_input[i];
- outputb.add(n, *m_onehalf);
- }
- double d = m_bias->getDoubleValue() * m_bias->getIsNegative() + (outputb.getDoubleValue() - outputa.getDoubleValue());
- return StochasticNum(d, 500);
- }
- StochasticNum::StochasticNum(long size) : m_bits(size), m_size(size)
- {}
- StochasticNum::StochasticNum(double value, long size) : m_bits(size), m_size(size)
- {
- uint8_t xor;
- double rng;
- for (int i = 0; i < size; i++)
- {
- xor = xor8();
- rng = (double) xor / (double)UINT8_MAX;
- if (rng < value)
- m_bits[i] = 1;
- }
- }
- StochasticNum::StochasticNum(double value, long size, bool isNeg) : m_bits(size), m_size(size), m_isneg(isNeg)
- {
- uint8_t xor;
- double rng;
- for (int i = 0; i < size; i++)
- {
- xor = xor8();
- rng = (double) xor / (double)UINT8_MAX;
- if (rng < value)
- m_bits[i] = 1;
- }
- }
- StochasticNum::StochasticNum(boost::dynamic_bitset<> bits)
- {
- m_bits = bits;
- }
- long StochasticNum::getSize()
- {
- return m_size;
- }
- void StochasticNum::setValue(double value, long size)
- {
- m_bits.resize(size);
- uint8_t xor;
- double rng;
- for (int i = 0; i < size; i++)
- {
- xor = xor8();
- rng = (double) xor / (double)UINT8_MAX;
- if (rng < value)
- m_bits[i] = 1;
- }
- }
- double StochasticNum::getDoubleValue()
- {
- return (double)m_bits.count() / (double)m_bits.size();
- }
- void StochasticNum::setIsNegative(bool neg)
- {
- m_isneg = neg;
- }
- bool StochasticNum::getIsNegative()
- {
- return m_isneg;
- }
- const StochasticNum StochasticNum::operator* (StochasticNum& other)
- {
- return StochasticNum(m_bits &= other.m_bits);
- }
- const StochasticNum StochasticNum::add(StochasticNum& other, StochasticNum& select)
- {
- return StochasticNum((select.m_bits.flip() &= m_bits) |= (other.m_bits &= select.m_bits.flip()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement