コード例 #1
0
ファイル: views.py プロジェクト: ivalykhin/neirohome
def predict(request, neironet_id):
    net = get_object_or_404(NeuralNet, pk=neironet_id)
    try:
        loaded_net = loadNet(net.neironet_file)
        data_list = []
        data_string = ""
        for i in range(0, net.number_of_inputs):
            value = request.POST['quote_' + str(i)].replace(',', '.').strip()
            data_list.append(float(value))
            data_string += value + ', '
        prediction_result = loaded_net.activate(data_list)[0]
        print prediction_result
    except (IOError, NeuralNet.DoesNotExist):
        # Redisplay the poll voting form.
        return render_to_response('neironet_detail.html', {
            'net': net,
            'error_message': "Wrong net file.",
        },
                                  context_instance=RequestContext(request))
    else:
        pred = Prediction(neiro_net=net,
                          input_data=data_string[:-2],
                          output_data=prediction_result,
                          predicted_on_date=now().date() + timedelta(days=1))
        pred.save()
        context = RequestContext(request, {
            'prediction': pred,
        })
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(
            reverse('prediction_research.views.prediction_detail',
                    args=(pred.id, )))
コード例 #2
0
ファイル: views.py プロジェクト: ivalykhin/neirohome
def predict(request, neironet_id):
    net = get_object_or_404(NeuralNet, pk=neironet_id)
    try:
        loaded_net = loadNet(net.neironet_file)
        data_list = []
        data_string = ""
        for i in range(0, net.number_of_inputs):
            value = request.POST['quote_' + str(i)].replace(',', '.').strip()
            data_list.append(float(value))
            data_string += value + ', '
        prediction_result = loaded_net.activate(data_list)[0]
        print prediction_result
    except (IOError, NeuralNet.DoesNotExist):
        # Redisplay the poll voting form.
        return render_to_response('neironet_detail.html', {
            'net': net,
            'error_message': "Wrong net file.",
        }, context_instance=RequestContext(request))
    else:
        pred = Prediction(neiro_net=net, input_data=data_string[:-2], output_data=prediction_result,
                          predicted_on_date=now().date()+timedelta(days=1))
        pred.save()
        context = RequestContext(request, {
        'prediction': pred,
    })
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('prediction_research.views.prediction_detail', args=(pred.id,)))
コード例 #3
0
ファイル: models.py プロジェクト: ivalykhin/neirohome
 def makePrediction(self, input_data_list, predicted_on_date, is_auto):
     loaded_net = loadNet(self.neuronet_file)
     prediction_result = loaded_net.activate(input_data_list)[0]
     input_data_string = ", ".join(map(str, input_data_list))
     pred = Prediction(neiro_net=self, input_data=input_data_string, output_data=prediction_result,
                       predicted_on_date=predicted_on_date, prediction_is_automate=is_auto)
     pred.save()
コード例 #4
0
 def makePrediction(self, input_data_list, predicted_on_date, is_auto):
     loaded_net = loadNet(self.neuronet_file)
     prediction_result = loaded_net.activate(input_data_list)[0]
     input_data_string = ", ".join(map(str, input_data_list))
     pred = Prediction(neiro_net=self,
                       input_data=input_data_string,
                       output_data=prediction_result,
                       predicted_on_date=predicted_on_date,
                       prediction_is_automate=is_auto)
     pred.save()
コード例 #5
0
ファイル: tasks.py プロジェクト: ivalykhin/neirohome
def makeAutomatePrediction():
    net_qs = NeuralNet.objects.all()
    count_usd_quotes = 4
    count_oil_quotes = 2
    today = now().date()
    quotes_qs = []
    if len(net_qs) == 0:
        print "No neironets for prediction"
    for net in net_qs:
        try:
            print net.name
            loaded_net = loadNet(net.neironet_file)
            if Quote.objects.filter(quote_date=today):
                prediction_date = today
            else:
                prediction_date = today - timedelta(days=1)
            if len(
                    Prediction.objects.filter(
                        neiro_net=net,
                        prediction_date__gte=today,
                        prediction_is_automate='Y')) == 0:
                quotes_qs = Quote.objects.filter(quote_date__gt=prediction_date - timedelta(days=count_usd_quotes),
                                                 quote_date__lte=prediction_date, quote_type='usd') | \
                            Quote.objects.filter(quote_date__gt=prediction_date - timedelta(days=count_oil_quotes),
                                                 quote_date__lte=prediction_date, quote_type='brent')
                if len(quotes_qs) == net.number_of_inputs:
                    quotes_list = []
                    for quote in quotes_qs.order_by('-quote_type',
                                                    'quote_date'):
                        quotes_list.append(quote.quote_value)
                    prediction_result = loaded_net.activate(quotes_list)[0]
                    print prediction_result
                    data_string = ", ".join(map(str, quotes_list))

                    pred = Prediction(neiro_net=net,
                                      input_data=data_string,
                                      output_data=prediction_result,
                                      predicted_on_date=prediction_date +
                                      timedelta(days=1),
                                      prediction_is_automate='Y')
                    pred.save()
                else:
                    print "Not enough parameters for prediction"
            else:
                print "Today automatic prediction already exist"
        except IOError:
            print "Neironet file is not exist"