// Run the regression
435809
func (r *Regression) Run() error {
	if !r.initialised {
		return errNotEnoughData
	}
	if r.hasRun {
		return errRegressionRun
	}

	//apply any features crosses
	r.applyCrosses()
	r.hasRun = true

	observations := len(r.data)
	numOfvars := len(r.data[0].Variables)

	if observations < (numOfvars + 1) {
		return errTooManyvars
	}

	// Create some blank variable space
	observed := mat.NewDense(observations, 1, nil)
	variables := mat.NewDense(observations, numOfvars+1, nil)

	for i := 0; i < observations; i++ {
		observed.Set(i, 0, r.data[i].Observed)
		for j := 0; j < numOfvars+1; j++ {
			if j == 0 {
				variables.Set(i, 0, 1)
			} else {
				variables.Set(i, j, r.data[i].Variables[j-1])
			}
		}
	}

	// Now run the regression
	_, n := variables.Dims() // cols
	qr := new(mat.QR)
	qr.Factorize(variables)
	q := qr.QTo(nil)
	reg := qr.RTo(nil)

	qtr := q.T()
	qty := new(mat.Dense)
	qty.Mul(qtr, observed)

	c := make([]float64, n)
	for i := n - 1; i >= 0; i-- {
		c[i] = qty.At(i, 0)
		for j := i + 1; j < n; j++ {
			c[i] -= c[j] * reg.At(i, j)
		}
		c[i] /= reg.At(i, i)
	}

	// Output the regression results
	r.coeff = make(map[int]float64, numOfvars)
	for i, val := range c {
		r.coeff[i] = val
		if i == 0 {
			r.Formula = fmt.Sprintf("Predicted = %.2f", val)
		} else {
			r.Formula += fmt.Sprintf(" + %v*%.2f", r.GetVar(i-1), val)
		}
	}

	r.calcPredicted()
	r.calcVariance()
	r.calcR2()
	return nil
}
707055
func (tm *transactionManager) run() {
	var q *query

	for {
		select {
		case q = <-tm.queryChan:
			go tm.query(q, tm.dht.Try)
		}
	}
}
1085065
func (c *dumpCommand) Run(ctx *cmd.Context) error {
	client, err := c.getAPI()
	if err != nil {
		return err
	}
	defer client.Close()

	_, modelDetails, err := c.ModelCommandBase.ModelDetails()
	if err != nil {
		return errors.Annotate(err, "getting model details")
	}

	modelTag := names.NewModelTag(modelDetails.ModelUUID)
	results, err := client.DumpModel(modelTag, c.simplified)
	if err != nil {
		return err
	}

	return c.out.Write(ctx, results)
}
702744
func (mr *ModRunner) Run() error {
	for {
		modchan := make(chan *moddwatch.Mod, 1024)
		err := mr.runOnChan(modchan, func() {})
		if err != nil {
			return err
		}
	}
}
1180379
func (e *UserSummary) Run(m libkb.MetaContext) error {
	sums, err := e.get(m)
	if err != nil {
		return err
	}
	e.summaries = sums
	return nil
}
492053
func (d *LSM303) Run() error {
	go func() {
		d.quit = make(chan struct{})

		timer := time.Tick(time.Duration(d.Poll) * time.Millisecond)

		var heading float64

		for {
			select {
			case <-timer:
				h, err := d.measureHeading()
				if err == nil {
					heading = h
				}
				if err == nil && d.headings == nil {
					d.headings = make(chan float64)
				}
			case d.headings <- heading:
			case <-d.quit:
				d.headings = nil
				return
			}

		}
	}()

	return nil
}
390972
func (a *adapter) Run() error {
	prompt()

	go func() {
		for {
			line, _, err := a.in.ReadLine()
			message := a.newMessage(string(line))

			if err != nil {
				if err == io.EOF {
					break
					// a.Robot.signalChan <- syscall.SIGTERM
				}
				fmt.Println("error:", err)
			}
			a.Receive(message)
			prompt()
		}
	}()

	<-a.quit
	return nil
}
484180
func (m *Main) Run() error {
	if m.Seed == -1 {
		m.Seed = time.Now().UnixNano()
	}

	schema := gopilosa.NewSchema()
	idx := schema.Index(m.Index)
	idx.Field(m.Field, gopilosa.OptFieldTypeSet(gopilosa.CacheTypeRanked, 50000))
	indexer, err := pdk.SetupPilosa(m.PilosaHosts, m.Index, schema, m.BatchSize)
	if err != nil {
		return errors.Wrap(err, "setting up Pilosa")
	}

	ug := newUserGetter(m.Seed)

	for i := uint64(0); i < m.Num; i++ {
		indexer.AddColumn(m.Field, i, ug.ID())
	}

	return errors.Wrap(indexer.Close(), "closing indexer")
}
306903
func (mod *CleverbotBee) Run(eventChan chan bees.Event) {
	mod.evchan = eventChan

	client, err := cleverbot.New(mod.api_user, mod.api_key, mod.session_nick)
	if err != nil {
		mod.LogErrorf("Failed to start session: %v", err)
		return
	}
	mod.client = client

	select {
	case <-mod.SigChan:
		return
	}
}
517836
func (re *JSRE) Run(code string) (v otto.Value, err error) {
	re.Do(func(vm *otto.Otto) { v, err = vm.Run(code) })
	return v, err
}
666394
func (x *xdsBalancer) run() {
	for {
		select {
		case update := <-x.grpcUpdate:
			x.handleGRPCUpdate(update)
		case update := <-x.xdsClientUpdate:
			x.handleXDSClientUpdate(update)
		case <-x.timer.C: // x.timer.C will block if we are not in fallback monitoring stage.
			x.switchFallback()
		case <-x.noSubConnAlert: // x.noSubConnAlert will block if we are not in fallback monitoring stage.
			x.switchFallback()
		case <-x.ctx.Done():
			if x.client != nil {
				x.client.close()
			}
			if x.xdsLB != nil {
				x.xdsLB.Close()
			}
			if x.fallbackLB != nil {
				x.fallbackLB.Close()
			}
			return
		}
	}
}
1346286
func (s *StatRepo) Run() {
	done := false

	for !done {
		select {
		case stat := <-s.rawStats:
			log.Debugf("StatRepo got %+v", *stat)
			s.insertRawStat(stat)
		case done = <-s.shutdown:
			log.Debug("StatRepo shutting down ", time.Now())
		case <-time.After(time.Second * 1):
			log.Debug("StatRepo Run() timeout ", time.Now())
		}
	}

	log.Info("StatRepo InsertRawStats() exiting ", time.Now())
}
1344275
func (d *BH1750FVI) Run() {
	go func() {
		d.quit = make(chan bool)

		timer := time.Tick(time.Duration(d.Poll) * time.Millisecond)

		var lighting float64

		for {
			select {
			case d.lightingReadings <- lighting:
			case <-timer:
				l, err := d.measureLighting()
				if err == nil {
					lighting = l
				}
				if err == nil && d.lightingReadings == nil {
					d.lightingReadings = make(chan float64)
				}
			case <-d.quit:
				d.lightingReadings = nil
				return
			}
		}
	}()
	return
}
194537
func (c *loginCommand) Run(ctx *cmd.Context) error {
	errout := interact.NewErrWriter(ctx.Stdout)
	c.pollster = interact.New(ctx.Stdin, ctx.Stderr, errout)

	err := c.run(ctx)
	if err != nil && c.onRunError != nil {
		c.onRunError()
	}
	return err
}
325874
func (e *columnEvaluator) run(ctx sessionctx.Context, input, output *chunk.Chunk) {
	for inputIdx, outputIdxes := range e.inputIdxToOutputIdxes {
		output.SwapColumn(outputIdxes[0], input, inputIdx)
		for i, length := 1, len(outputIdxes); i < length; i++ {
			output.MakeRef(outputIdxes[0], outputIdxes[i])
		}
	}
}
556516
func (e *EvaluatorSuite) Run(ctx sessionctx.Context, input, output *chunk.Chunk) error {
	if e.defaultEvaluator != nil {
		err := e.defaultEvaluator.run(ctx, input, output)
		if err != nil {
			return err
		}
	}

	if e.columnEvaluator != nil {
		e.columnEvaluator.run(ctx, input, output)
	}
	return nil
}
177660
func (m *Main) Run() error {
	conf := sarama.NewConfig()
	conf.Version = sarama.V0_10_0_0
	conf.Producer.Return.Successes = true
	producer, err := sarama.NewSyncProducer(m.Hosts, conf)
	if err != nil {
		return errors.Wrap(err, "getting new producer")
	}
	defer producer.Close()

	for ticker := time.NewTicker(m.Rate); true; <-ticker.C {
		ev := fake.GenEvent()
		msg := &sarama.ProducerMessage{Topic: m.Topic, Value: JSONEvent(*ev)}
		_, _, err := producer.SendMessage(msg)
		if err != nil {
			log.Printf("Error sending message: '%v', backing off", err)
			time.Sleep(time.Second * 10)
		}
	}
	return nil
}