text:
<file_sep>//  PART ONE

// PE suggestion

const themes = {
    blue: {
        jumbotron: "#588fbd",
        primaryButtonColour: "#ffa500",
        secondaryButtonColour: "black",
        secondaryButtonTextColor: "white",
    },
    orange: {
        jumbotron: "#f0ad4e",
        primaryButtonColour: "#5751fd",
        secondaryButtonColour: "#31b0d5",
        secondaryButtonTextColor: "white",
    },
    green: {
        jumbotron: "#87ca8a",
        primaryButtonColour: "black",
        secondaryButtonColour: "#8c9c08",
        secondaryButtonTextColor: "#292b2c",
    },
};

let buttonList = document.querySelectorAll(".primary-content > button");            //Here we get a node list which contains the 3 buttons
for (i = 0; i < buttonList.length; i++) {                                           //Since it is an array like list, we can iterate over it and add event listener to each one
    buttonList[i].addEventListener("click", changeColour)
}

function applyColour(colour) {
    let jumbo = document.querySelector(".jumbotron");
    jumbo.style.backgroundColor = themes[colour].jumbotron;

    let donate = document.querySelector(".buttons > .btn-primary");
    donate.style.backgroundColor = themes[colour].primaryButtonColour;

    let volunteer = document.querySelector(".buttons > .btn-secondary")
    volunteer.style.backgroundColor = themes[colour].secondaryButtonColour;
    volunteer.style.color = themes[colour].secondaryButtonTextColor;
}

function changeColour(e) {
    if (e.target.outerText === "Blue") {
        applyColour("blue")

    } else if (e.target.outerText === "Orange") {
        applyColour("orange")

    } else if (e.target.outerText === "Green") {
        applyColour("green");
    }
}

// My solution

// function changeColour(e) {                                                          //We are adding the "event object" as a parameter
//     if (e.target.outerText === "Blue") {                                              //the property "e.target" have another property called "outerText",
//         let jumbotron = document.querySelector(".jumbotron");                       //Which gives us a value of the text inside the button e.g. <button> Blue </button> is same as <button> e.target.outerText </button>
//         jumbotron.style.backgroundColor = "#588fbd";

//         let donate = document.querySelector(".buttons > .btn-primary");
//         donate.style.backgroundColor = "#ffa500";

//         let volunteer = document.querySelector(".buttons > .btn-secondary")
//         volunteer.style.backgroundColor = "black";
//         volunteer.style.color = "white";

//     } else if (e.target.outerText === "Orange") {
//         let jumbotron = document.querySelector(".jumbotron");
//         jumbotron.style.backgroundColor = "#f0ad4e";

//         let donate = document.querySelector(".buttons > .btn-primary");
//         donate.style.backgroundColor = "#5751fd";

//         let volunteer = document.querySelector(".buttons > .btn-secondary")
//         volunteer.style.backgroundColor = "#31b0d5";
//         volunteer.style.color = "white";
//     } else if (e.target.outerText === "Green") {
//         let jumbotron = document.querySelector(".jumbotron");
//         jumbotron.style.backgroundColor = "#87ca8a";

//         let donate = document.querySelector(".buttons > .btn-primary");
//         donate.style.backgroundColor = "black";

//         let volunteer = document.querySelector(".buttons > .btn-secondary")
//         volunteer.style.backgroundColor = "#8c9c08";
//     }
// }

// PART TWO

let formButton = document.querySelector("form > button");
formButton.addEventListener("click", validateForm)

function validateForm(e) {
    e.preventDefault()
    let email = document.querySelector("#exampleInputEmail1");
    if (email.value.includes("@") === false) {
        email.classList.add("input-error")
    }

    let name = document.querySelector("#example-text-input");
    if (name.value.length === 0) {
        name.classList.add("input-error")
    }

    let description = document.querySelector("#exampleTextarea");
    if (description.value.length === 0) {
        description.classList.add("input-error")
    }

    if (email.value.includes("@") && name.value.length > 0 && description.value.length > 0) {
        email.value = "";
        email.classList.add("remove-error");

        name.value = "";
        name.classList.add("remove-error");

        description.value = "";
        description.classList.add("remove-error");

        alert("Thank you for filling out the form")
    }
}

<file_sep>function listOfColours(colours) {
  let contents = document.querySelector("#content");
  let dropMenu = document.createElement("select");
  let paragraph = document.createElement("p");
  paragraph.innerText = `You have selected:`;

  for (let colour of colours) {
    let option = document.createElement("option");
    option.innerText = colour;
    dropMenu.appendChild(option);
  }

  dropMenu.addEventListener("change", addColour);

  function addColour(e) {
    paragraph.style.backgroundColor = e.target.value;
    paragraph.innerText = `You have selected: ${e.target.value}`;
  }

  contents.appendChild(paragraph);
  contents.appendChild(dropMenu);
}

const colours = ["red", "blue", "green", "yellow", "pink", "brown"];

listOfColours(colours);
<file_sep>function shoppingList(arrayOfItems) {
  let contents = document.querySelector("#content");
  let ourList = document.createElement("ul");

  for (let item of arrayOfItems) {
    let eachItem = document.createElement("li");
    eachItem.innerText = item;
    ourList.appendChild(eachItem);
  }
  contents.appendChild(ourList);

}

let shopping = ["Milk", "Bread", "Eggs", "A Dinosaur", "Cake", "Sugar", "Tea"];

shoppingList(shopping);
<file_sep>function todoList(todos) {
  let contents = document.querySelector("#content");

  let pageHeader = document.createElement("h1");                                //Create Header and append it to the <div> with Id = #content
  pageHeader.innerText = "Our To Do List:";
  contents.appendChild(pageHeader);

  let toDoList = document.createElement("ul");                                  //Create the "ul" tag

  for (let action of todos) {                                                   //Iterate through the list
    let eachItem = document.createElement("li")                                 //In each iteration create a list "li", then write a text inside and style the text
    eachItem.innerText = action.todo;
    eachItem.classList.add("my-item")
    eachItem.addEventListener("click", addLineThrough)                          //Add an event listener and its callback function.

    toDoList.appendChild(eachItem);                                             //Append each new list "li" to our "ul" at the top
  }

  contents.appendChild(toDoList);                                              //Append the unordered list "ul" to the <div> with Id = #content
}

function addLineThrough(e) {
  if (e.target.style.textDecoration !== "line-through") {
    e.target.classList.toggle("add-line-through");
  } else {
    e.target.classList.toggle("my-item");
  }
}

const ourTodos = [
  { todo: "wash the dishes" },
  { todo: "walk the dog" },
  { todo: "learn javascript" },
  { todo: "go shopping" }
];

todoList(ourTodos);

repo_language: JavaScript


text:
<repo_name>ToverPomelo/Hello-World<file_sep>/README.md
# Hello-World
The first repository

It's the first time for me to learn about GitHub.
Wonderful.

branch_name: refs/heads/master

repo_language: Markdown

repo_name: ToverPomelo/Hello-World


text:
<repo_name>jomar-12/ToolKitMarkupProject<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject/CustomControl/LoginButton.cs
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

namespace ToolKitMarkupProject.CustomControl
{
    public class LoginButton : Button { }
}
<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject/App.xaml.cs
using ToolKitMarkupProject.View.Pages;
using ToolKitMarkupProject.ViewModels;
using Xamarin.Forms;

namespace ToolKitMarkupProject
{
    public partial class App : Application
    {
        public static new App Current => (App)Application.Current;
        public LoginViewModel LoginViewModel { get; set; }

        public App()
        {
            InitializeComponent();

            MainPage = new NavigationPage(new LoginPage());
        }

        protected override void OnStart()
        {
        }

        protected override void OnSleep()
        {
        }

        protected override void OnResume()
        {
        }
    }
}<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject/View/Pages/BaseContentPage.cs
using System;
using System.Collections.Generic;
using System.Text;
using ToolKitMarkupProject.ViewModels;
using Xamarin.Forms;

namespace ToolKitMarkupProject.View.Pages
{
    public class BaseContentPage : ContentPage
    {
        protected static double PageMarginSize = 12, HeaderHeight = 26, CellHorizontalMarginSize = 16, CellVerticalMarginSize = 12;
    }

    public class BaseContentPage<ViewModelType> : BaseContentPage where ViewModelType : BaseViewModel
    {
        protected ViewModelType ViewModel { get { return (ViewModelType)BindingContext; } set { BindingContext = value; } }
    }
}<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject/View/Pages/LoginPage.logic.cs
using System;
using System.Collections.Generic;
using System.Text;
using ToolKitMarkupProject.ViewModels;

namespace ToolKitMarkupProject.View.Pages
{
    public partial class LoginPage
    {
        public LoginPage() => Initialize();

        public void Initialize()
        {
            BindingContext = new LoginViewModel();

            Build();
        }
    }
}<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject/View/Pages/LoginPage.cs
using System;
using System.Collections.Generic;
using System.Text;

using ToolKitMarkupProject.CustomControl;
using ToolKitMarkupProject.ViewModels;
using Xamarin.CommunityToolkit.Markup;
using Xamarin.Forms;

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(null, "ENC1003")]

namespace ToolKitMarkupProject.View.Pages
{
    public partial class LoginPage : ContentPage
    {
        private void Build()
        {
            var app = App.Current;
            var vm = app.LoginViewModel;

            NavigationPage.SetHasNavigationBar(this, false);
            BackgroundImageSource = "bgXamarin.png";

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,

                Children =
                {
                    new Image{ Source="Logo.png"} .Margins(105,120,105,95),

                    new RoundedEntry{ Placeholder = "Email",HorizontalTextAlignment= TextAlignment.Start,TextColor = Color.White, PlaceholderColor= Color.White}
                    .Bind(nameof(vm.Username)).Margin(60, 5),

                    new RoundedEntry{ Placeholder = "Password", HorizontalTextAlignment= TextAlignment.Start, IsPassword = true, TextColor = Color.White, PlaceholderColor=Color.White}
                    .Bind(nameof(vm.Password)).Margin(60, 5),

                    new Label{ Text="Forgot your Password?", HorizontalTextAlignment = TextAlignment.Center, TextColor=Color.White}
                    .Paddings(0, 10, 0, 50).BindTapGesture(nameof(vm.ForgotPassword)),

                    new LoginButton{ Text="Sign in", CharacterSpacing=1 ,CornerRadius = 30, BackgroundColor= Color.Transparent,TextColor=Color.White ,BorderColor=Color.White}
                    .Margin(90,0).Height(60).FontSize(23).Font(bold: true).Bind(nameof(vm.LoginButton)),

                    new Frame {
                        BackgroundColor = Color.FromRgba(0,0,0,0.4),
                        HeightRequest = 6,
                        VerticalOptions = LayoutOptions.EndAndExpand,
                        Content = new StackLayout
                        {
                            Orientation = StackOrientation.Horizontal,
                            HorizontalOptions = LayoutOptions.Center,

                            Children =
                            {
                                new Label
                                {
                                    Text = "Do not have an account?",
                                    TextColor = Color.White,
                                    VerticalTextAlignment = TextAlignment.Center,
                                    HorizontalTextAlignment = TextAlignment.Center,
                                    Padding = -5
                                },
                                new Label
                                {
                                    Text = "Create Acount.",
                                    TextColor = Color.White,
                                    VerticalTextAlignment = TextAlignment.Center,
                                    HorizontalTextAlignment = TextAlignment.Center,
                                    Padding = -5
                                }
                                .Margin(10,0)
                                .Font(bold: true)
                                .FontSize(14)
                                .BindTapGesture(nameof(vm.CreateAccount))
                            }
                        }
                    }

                }
            };

        }
    }
}<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject/ViewModels/LoginViewModel.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace ToolKitMarkupProject.ViewModels
{
    public class LoginViewModel : BaseViewModel
    {
        private string _username;
        private string _password;
        private bool _isbusy;

        public LoginViewModel()
        {
            LoginButton = new Command(async () => await LoginValiation());
            ForgotPassword = new Command(async () => await ForgotPasswordAction());
            CreateAccount = new Command(async () => await CreateAccountAction());
        }

        public Command LoginButton { get; set; }
        public Command ForgotPassword { get; set; }
        public Command CreateAccount { get; set; }

        public string Username
        {
            get { return _username; }
            set
            {
                _username = value;

                OnPropertyChanged();
            }
        }
        public string Password
        {
            get { return _password; }
            set
            {
                _password = value;

                OnPropertyChanged();
            }
        }

        public bool IsBusy
        {
            get { return _isbusy; }
            set
            {
                IsBusy = value;

                OnPropertyChanged();
            }
        }

        private async Task CreateAccountAction()
        {
            await Application.Current.MainPage.DisplayAlert("Welcome!", "Account created", "Ok");
        }
        private async Task ForgotPasswordAction()
        {
            await Application.Current.MainPage.DisplayAlert("Don't worry", "Password has been sent to your email", "Ok");
        }

        private async Task LoginValiation()
        {
            IsBusy = true;
            await Task.Delay(3000);
            IsBusy = false;

            bool IsValidated = Username == "fulano14" && Password == "<PASSWORD>";
            var app = Application.Current.MainPage;

            if (IsValidated) await app.DisplayAlert($"Hi {Username}!", "You are sign in.", "Ok");
            else await app.DisplayAlert("Ups...", "wrong username or password", "Ok");
        }
    }
}<file_sep>/ToolKitMarkupProject/ToolKitMarkupProject.Android/LoginButtonRendererAndroid.cs
using Android.Graphics.Drawables;
using System;
using ToolKitMarkupProject.CustomControl;
using ToolKitMarkupProject.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

#pragma warning disable CS0612 // Type or member is obsolete
[assembly: ExportRenderer(typeof(LoginButton), typeof(LoginButtonRendererAndroid))]
#pragma warning restore CS0612 // Type or member is obsolete

namespace ToolKitMarkupProject.Droid
{
    [Obsolete]
    public class LoginButtonRendererAndroid : ButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null)
            {
                var gradientDrawable = new GradientDrawable();
                gradientDrawable.SetCornerRadius(80f);
                gradientDrawable.SetStroke(5, Android.Graphics.Color.White);
                gradientDrawable.SetColor(Android.Graphics.Color.Transparent);
                Control.SetBackground(gradientDrawable);
            }
        }
    }
}

branch_name: refs/heads/main

repo_language: C#


text:
<repo_name>williamGD/Notes<file_sep>/DPM/AboutDPM.md
##DPM combine Filter Channels Features

Filter Channels Features : get [x1,y1,w,h,socre]

DPM: get [x1,y1,w,h,score]

都需要设置阈值，并且已经在.c文件中筛选过了，如果要改变他们置信度就需要修改.c文件。

先尝试直接在已经置信度阈值筛选后的再次选择，主要集中在将两个置信度拉伸到同一个区间，并且设置各自权重，用投票法？

	方法1：
	两种方法尽量不漏检，然后采用投票法，根据置信度确定投票权多少，确定出一个mask矩阵。

##DPM and FilterACF

	Test
	降低两种方法的漏检率，让两种方法检查到尽可能多的框，
	然后尝试将两种方法同时击中某个区域的时，确定为行人，这是初步的筛选。

	击中的概念为当两个框击中的时候，有一方的中心点在另一方的中间，这为击中。
	击中后框的融合？
	两框中心两个点的中心，为新框的中心，两框长宽乘上权重之和。
	之后对于所有结合的框置信度进行排序，用一个阈值进行截断低于的行人。

---
	Test
	先做一次击中的筛选，只有两个检测算法同时击中某个区域，此区域才算是行人。
	击中的话指的是他们的重叠率达到百分之五十。
	然后进行置信度重新统计的map图谱。
	固定某一框，检测所有的框的重叠，如果达到一定值，将置信度低的舍去。

	<file_sep>/README.md
# Notes

读书记录
<file_sep>/DPM/DPM移植.md
##DPM Code

 - Model format documentation in doucumentation.txt

Model paraments:

    filters:
    rules:
    symols:
    start:

**'model.thresh' defines a threshold that can be used in the 'detect' function to obtain a high recall rate.**

><NAME>, <NAME>, <NAME>, <NAME>
Object Detection with Discriminatively Trained Part Based Models
IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 32, No. 9, Sep. 2010

##DPM平台移植

**因为DPM需要在Linux下运行，所以将其运行在windows下需要进行修改**

 - DPM版本：voc-release4.01
 - PC：windows 7 64位
 - 编译器：Microsoft Visual C++ 2013 Professional

### How to run objection Detection with Discriminatively Trained Part Based Models

 - 修改dt.cc,fconv.cc,features.cc,getdetections.cc,resize.cc的后缀.cc为.cpp;
 - dt.cpp 中 添加

---
    #define int32_t int

  - feature.cpp 加入 round()如下，必要的话

---

  - resize.cpp 加入和修改

---

    #define bzero(a,b) memset(a,0,b)

    //如果必要,需要添加这段代码
    int round(float a)
    {
           float tmp = a - (int)a;
           if( tmp >= 0.5 )
               return (int)a + 1;
           else
               return (int)a;
    }

---

    //alphainfo ofs[len];
    struct alphainfo *ofs = (struct alphainfo *)malloc(sizeof(struct alphainfo)*len);

---
    free(ofs);//注意释放

   - compile.m 配置

---
    mex -O resize.cpp
    mex -O dt.cpp
    mex -O features.cpp
    mex -O getdetections.cpp
    mex -O fconv.cpp

   - 编译过后就可以运行demo.m

### How to train models of Object Detection with Discriminatively Trained Part Based Models

 - 首先下载voc的数据库和相应的VOCdevkit。（注意把数据也放在VOCdevkit的目录中）

 - pascal_data.m文件添加一段

---
    numpos = numpos+1;
    %
    if exist([VOCopts.datadir rec.imgname])==0
    continue;
    end
    %
    pos(numpos).im = [VOCopts.datadir rec.imgname];

 - pascal.m 文件修改

---
    %unix(['rm ' tmpdir cls '.dat']);
    system(['del ' tmpdir cls '.dat']);

  - rewritedat.m 修改

---
    % unix(['mv ' datfile ' ' oldfile]);
    movefile(datfile,oldfile);

---

	% unix(['rm ' oldfile]);
	delete(oldfile);

---

	% unix(['cp ' inffile ' ' oldfile]);
	system(['copy ' inffile ' ' oldfile]);

---

修改原因：训练时会产生越界

	% sort indexes so we never have to seek before the current position
	% I = sort(I);
	%
	% pos = 1;
	% for i = 1:length(I)
	%   cnt = I(i)-pos;
	%   while cnt > 0
	%     % + 2 to include the num non-zero blocks and example length
	%     info = fread(fin, labelsize+2, 'int32');
	%     dim = info(end);
	%     fseek(fin, dim*4, 0);
	%     cnt = cnt - 1;
	%   end
	%   y = fread(fin, labelsize+2, 'int32');
	%   dim = y(end);
	%   x = fread(fin, dim, 'single');
	%   fwrite(fout, y, 'int32');
	%   fwrite(fout, x, 'single');
	%   pos = I(i)+1;
	% end

	I = sort(I);

	pos = 1;
	for i = 1:length(I)
	  cnt = I(i)-pos;
	  while cnt > 0
	    % + 2 to include the num non-zero blocks and example length
	    info = fread(fin, labelsize+2, 'int32');
	    if length(info) == 0
	        dim = 0;
	    else
	        dim = info(end);
	    end
	    %dim = info(end);
	    fseek(fin, dim*4, 0);
	    cnt = cnt - 1;
	  end
	  y = fread(fin, labelsize+2, 'int32');
	  %//!
	  if length(y) == 0
	      dim = 0;
	  else
	      dim = y(end);
	  end
	  x = fread(fin, dim, 'single');
	  fwrite(fout, y, 'int32');
	  fwrite(fout, x, 'single');
	  pos = I(i)+1;
	end

   - train.m 修改

---

	% cmd = sprintf('./learn %.6f %.6f %s %s %s %s %s %s %s %s %s', ...
	%                  C, J, hdrfile, datfile, modfile, inffile, lobfile, ...
	%                  cmpfile, objfile, cachedir, logtag);

    cmd = sprintf('learn %.6f %.6f %s %s %s %s %s %s %s %s %s', ...
                   C, J, hdrfile, datfile, modfile, inffile, lobfile, ...
                   cmpfile, objfile, cachedir, logtag);

   - procid.m 修改

---

	% i = strfind(d, '/');
	i = strfind(d, '\');

   - learn.cc 变成 learn.cpp 建一个工程进行编译，修改的代码如下，编译后的.exe 文件放置于 voc-release4.01文件夹下

---

	#include <stdio.h>
	#include <stdlib.h>
	#include <string>
	#include <math.h>
	#include <time.h>
	#include <errno.h>
	#include <fstream>
	#include <iostream>
	//#include "stdafx.h"

	using namespace std;

	/*
	* Optimize LSVM objective function via gradient descent.
	*
	* We use an adaptive cache mechanism.  After a negative example
	* scores beyond the margin multiple times it is removed from the
	* training set for a fixed number of iterations.
	*/

	// Data File Format
	// EXAMPLE*
	//
	// EXAMPLE:
	//  long label          ints
	//  blocks              int
	//  dim                 int
	//  DATA{blocks}
	//
	// DATA:
	//  block label         float
	//  block data          floats
	//
	// Internal Binary Format
	//  len           int (byte length of EXAMPLE)
	//  EXAMPLE       <see above>
	//  unique flag   byte

	// number of iterations

	/*#ifndef DRAND48_H
	#define DRAND48_H

	#include <stdlib.h>  */

	//#define m 0x100000000LL
	//#define a 0x5DEECE66DLL
	//static unsigned long long seed = 1;
	//#endif
	//#define Infinity 1.0+308

	#define ITER 10e6

	// minimum # of iterations before termination
	#define MIN_ITER 5e6

	// convergence threshold
	#define DELTA_STOP 0.9995

	// number of times in a row the convergence threshold
	// must be reached before stopping
	#define STOP_COUNT 5

	// small cache parameters
	#define INCACHE 25
	#define MINWAIT (INCACHE+25)
	#define REGFREQ 20

	// error checking
	#define check(e) \
	(e ? (void)0 : (printf("%s:%u error: %s\n%s\n", __FILE__, __LINE__, #e, strerror(errno)), exit(1)))

	// number of non-zero blocks in example ex
	#define NUM_NONZERO(ex) (((int *)ex)[labelsize+1])

	// float pointer to data segment of example ex
	#define EX_DATA(ex) ((float *)(ex + sizeof(int)*(labelsize+3)))

	// class label (+1 or -1) for the example
	#define LABEL(ex) (((int *)ex)[1])

	// block label (converted to 0-based index)
	#define BLOCK_IDX(data) (((int)data[0])-1)

	// set to 0 to use max-component L2 regularization
	// set to 1 to use full model L2 regularization
	#define FULL_L2 0

	#define MNWZ 0x100000000
	#define ANWZ 0x5DEECE66D
	#define CNWZ 0xB16
	#define INFINITY_my 0xFFFFFFFFF

	int labelsize;
	int dim;

	static unsigned long long seed = 1;

	double drand48(void)
	{
		seed = (ANWZ * seed + CNWZ) & 0xFFFFFFFFFFFFLL;
		unsigned int x = seed >> 16;
		return  ((double)x / (double)MNWZ);
	}

	//static unsigned long long seed = 1;

	void srand48(unsigned int i)
	{
		seed = (((long long int)i) << 16) | rand();
	}

	// comparison function for sorting examples
	int comp(const void *a, const void *b) {
		// sort by extended label first, and whole example second...
		int c = memcmp(*((char **)a) + sizeof(int),
			*((char **)b) + sizeof(int),
			labelsize*sizeof(int));
		if (c)
			return c;

		// labels are the same
		int alen = **((int **)a);
		int blen = **((int **)b);
		if (alen == blen)
			return memcmp(*((char **)a) + sizeof(int),
			*((char **)b) + sizeof(int),
			alen);
		return ((alen < blen) ? -1 : 1);
	}

	// a collapsed example is a sequence of examples
	struct collapsed {
		char **seq;
		int num;
	};

	// the two node types in an AND/OR tree
	enum node_type { OR, AND };

	// set of collapsed examples
	struct data {
		collapsed *x;
		int num;
		int numblocks;
		int numcomponents;
		int *blocksizes;
		int *componentsizes;
		int **componentblocks;
		float *regmult;
		float *learnmult;
	};

	// seed the random number generator with an arbitrary (fixed) value
	void seed_rand() {
		srand48(3);
		//srand(3);
	}

	static inline double min(double x, double y) { return (x <= y ? x : y); }
	static inline double max(double x, double y) { return (x <= y ? y : x); }

	// compute the score of an example
	static inline double ex_score(const char *ex, data X, double **w) {
		double val = 0.0;
		float *data = EX_DATA(ex);
		int blocks = NUM_NONZERO(ex);
		for (int j = 0; j < blocks; j++) {
			int b = BLOCK_IDX(data);
			data++;
			double blockval = 0;
			for (int k = 0; k < X.blocksizes[b]; k++)
				blockval += w[b][k] * data[k];
			data += X.blocksizes[b];
			val += blockval;
		}
		return val;
	}

	// return the value of the object function.
	// out[0] : loss on negative examples
	// out[1] : loss on positive examples
	// out[2] : regularization term's value
	double compute_loss(double out[3], double C, double J, data X, double **w) {
		double loss = 0.0;
	#if FULL_L2
		// compute ||w||^2
		for (int j = 0; j < X.numblocks; j++) {
			for (int k = 0; k < X.blocksizes[j]; k++) {
				loss += w[j][k] * w[j][k] * X.regmult[j];
			}
		}
	#else
		// compute max norm^2 component
		for (int c = 0; c < X.numcomponents; c++) {
			double val = 0;
			for (int i = 0; i < X.componentsizes[c]; i++) {
				int b = X.componentblocks[c][i];
				double blockval = 0;
				for (int k = 0; k < X.blocksizes[b]; k++)
					blockval += w[b][k] * w[b][k] * X.regmult[b];
				val += blockval;
			}
			if (val > loss)
				loss = val;
		}
	#endif
		loss *= 0.5;

		// record the regularization term
		out[2] = loss;

		// compute loss from the training data
		for (int l = 0; l <= 1; l++) {
			// which label subset to look at: -1 or 1
			int subset = (l * 2) - 1;
			double subsetloss = 0.0;
			for (int i = 0; i < X.num; i++) {
				collapsed x = X.x[i];

				// only consider examples in the target subset
				char *ptr = x.seq[0];
				if (LABEL(ptr) != subset)
					continue;

				// compute max over latent placements
				int M = -1;
				double V = -INFINITY_my;
				//double V = -NWZ;
				for (int m = 0; m < x.num; m++) {
					double val = ex_score(x.seq[m], X, w);
					if (val > V) {
						M = m;
						V = val;
					}
				}

				// compute loss on max
				ptr = x.seq[M];
				int label = LABEL(ptr);
				double mult = C * (label == 1 ? J : 1);
				subsetloss += mult * max(0.0, 1.0 - label*V);
			}
			loss += subsetloss;
			out[l] = subsetloss;
		}

		return loss;
	}

	// gradient descent
	void gd(double C, double J, data X, double **w, double **lb, char *logdir, char *logtag) {
		ofstream logfile;
		string filepath = string(logdir) + "/learnlog/" + string(logtag) + ".log";

		/*char* filepath;
		strcat(filepath,logdir);
		strcat(filepath,"/learnlog/");
		strcat(filepath,logtag);
		strcat(filepath,"/log");*/

		logfile.open(filepath.c_str());
		//logfile.open(filepath);
		logfile.precision(14);
		logfile.setf(ios::fixed, ios::floatfield);

		int num = X.num;

		// state for random permutations
		int *perm = (int *)malloc(sizeof(int)*X.num);
		check(perm != NULL);

		// state for small cache
		int *W = (int *)malloc(sizeof(int)*num);
		check(W != NULL);
		for (int j = 0; j < num; j++)
			W[j] = INCACHE;

		double prev_loss = 1E9;

		bool converged = false;
		int stop_count = 0;
		int t = 0;
		while (t < ITER && !converged) {
			// pick random permutation
			for (int i = 0; i < num; i++)
				perm[i] = i;
			for (int swapi = 0; swapi < num; swapi++) {
				int swapj = (int)(drand48()*(num - swapi)) + swapi;
				//int swapj = (int)(rand()*(num-swapi)) + swapi;
				int tmp = perm[swapi];
				perm[swapi] = perm[swapj];
				perm[swapj] = tmp;
			}

			// count number of examples in the small cache
			int cnum = 0;
			for (int i = 0; i < num; i++)
				if (W[i] <= INCACHE)
					cnum++;

			int numupdated = 0;
			for (int swapi = 0; swapi < num; swapi++) {
				// select example
				int i = perm[swapi];

				// skip if example is not in small cache
				if (W[i] > INCACHE) {
					W[i]--;
					continue;
				}

				collapsed x = X.x[i];

				// learning rate
				double T = min(ITER / 2.0, t + 10000.0);
				double rateX = cnum * C / T;

				t++;
				if (t % 100000 == 0) {
					double info[3];
					double loss = compute_loss(info, C, J, X, w);
					double delta = 1.0 - (fabs(prev_loss - loss) / loss);
					logfile << t << "\t" << loss << "\t" << delta << endl;
					if (delta >= DELTA_STOP && t >= MIN_ITER) {
						stop_count++;
						if (stop_count > STOP_COUNT)
							converged = true;
					}
					else if (stop_count > 0) {
						stop_count = 0;
					}
					prev_loss = loss;
					printf("\r%7.2f%% of max # iterations "
						"(delta = %.5f; stop count = %d)",
						100 * double(t) / double(ITER), max(delta, 0.0),
						STOP_COUNT - stop_count + 1);
					fflush(stdout);
					if (converged)
						break;
				}

				// compute max over latent placements
				int M = -1;
				double V = -INFINITY_my;
				//double V = -NWZ;
				for (int m = 0; m < x.num; m++) {
					double val = ex_score(x.seq[m], X, w);
					if (val > V) {
						M = m;
						V = val;
					}
				}

				char *ptr = x.seq[M];
				int label = LABEL(ptr);
				if (label * V < 1.0) {
					numupdated++;
					W[i] = 0;
					float *data = EX_DATA(ptr);
					int blocks = NUM_NONZERO(ptr);
					for (int j = 0; j < blocks; j++) {
						int b = BLOCK_IDX(data);
						double mult = (label > 0 ? J : -1) * rateX * X.learnmult[b];
						data++;
						for (int k = 0; k < X.blocksizes[b]; k++)
							w[b][k] += mult * data[k];
						data += X.blocksizes[b];
					}
				}
				else {
					if (W[i] == INCACHE)
						W[i] = MINWAIT + (int)(drand48() * 50);
					//W[i] = MINWAIT + (int)(rand()*50);
					else
						W[i]++;
				}

				// periodically regularize the model
				if (t % REGFREQ == 0) {
					// apply lowerbounds
					for (int j = 0; j < X.numblocks; j++)
						for (int k = 0; k < X.blocksizes[j]; k++)
							w[j][k] = max(w[j][k], lb[j][k]);

					double rateR = 1.0 / T;

	#if FULL_L2
					// update model
					for (int j = 0; j < X.numblocks; j++) {
						double mult = rateR * X.regmult[j] * X.learnmult[j];
						mult = pow((1 - mult), REGFREQ);
						for (int k = 0; k < X.blocksizes[j]; k++) {
							w[j][k] = mult * w[j][k];
						}
					}
	#else
					// assume simple mixture model
					int maxc = 0;
					double bestval = 0;
					for (int c = 0; c < X.numcomponents; c++) {
						double val = 0;
						for (int i = 0; i < X.componentsizes[c]; i++) {
							int b = X.componentblocks[c][i];
							double blockval = 0;
							for (int k = 0; k < X.blocksizes[b]; k++)
								blockval += w[b][k] * w[b][k] * X.regmult[b];
							val += blockval;
						}
						if (val > bestval) {
							maxc = c;
							bestval = val;
						}
					}
					for (int i = 0; i < X.componentsizes[maxc]; i++) {
						int b = X.componentblocks[maxc][i];
						double mult = rateR * X.regmult[b] * X.learnmult[b];
						mult = pow((1 - mult), REGFREQ);
						for (int k = 0; k < X.blocksizes[b]; k++)
							w[b][k] = mult * w[b][k];
					}
	#endif
				}
			}
		}

		if (converged)
			printf("\nTermination criteria reached after %d iterations.\n", t);
		else
			printf("\nMax iteration count reached.\n", t);

		free(perm);
		free(W);
		logfile.close();
	}

	// score examples
	double *score(data X, char **examples, int num, double **w) {
		double *s = (double *)malloc(sizeof(double)*num);
		check(s != NULL);
		for (int i = 0; i < num; i++)
			s[i] = ex_score(examples[i], X, w);
		return s;
	}

	// merge examples with identical labels
	void collapse(data *X, char **examples, int num) {
		collapsed *x = (collapsed *)malloc(sizeof(collapsed)*num);
		check(x != NULL);
		int i = 0;
		x[0].seq = examples;
		x[0].num = 1;
		for (int j = 1; j < num; j++) {
			if (!memcmp(x[i].seq[0] + sizeof(int), examples[j] + sizeof(int),
				labelsize*sizeof(int))) {
				x[i].num++;
			}
			else {
				i++;
				x[i].seq = &(examples[j]);
				x[i].num = 1;
			}
		}
		X->x = x;
		X->num = i + 1;
	}

	int main(int argc, char **argv) {
		seed_rand();
		int count;
		data X;

		// command line arguments
		check(argc == 12);
		double C = atof(argv[1]);
		double J = atof(argv[2]);
		char *hdrfile = argv[3];
		char *datfile = argv[4];
		char *modfile = argv[5];
		char *inffile = argv[6];
		char *lobfile = argv[7];
		char *cmpfile = argv[8];
		char *objfile = argv[9];
		char *logdir = argv[10];
		char *logtag = argv[11];

		// read header file
		FILE *f = fopen(hdrfile, "rb");
		check(f != NULL);
		int header[3];
		count = fread(header, sizeof(int), 3, f);
		check(count == 3);
		int num = header[0];
		labelsize = header[1];
		X.numblocks = header[2];
		X.blocksizes = (int *)malloc(X.numblocks*sizeof(int));
		count = fread(X.blocksizes, sizeof(int), X.numblocks, f);
		check(count == X.numblocks);
		X.regmult = (float *)malloc(sizeof(float)*X.numblocks);
		check(X.regmult != NULL);
		count = fread(X.regmult, sizeof(float), X.numblocks, f);
		check(count == X.numblocks);
		X.learnmult = (float *)malloc(sizeof(float)*X.numblocks);
		check(X.learnmult != NULL);
		count = fread(X.learnmult, sizeof(float), X.numblocks, f);
		check(count == X.numblocks);
		check(num != 0);
		fclose(f);
		printf("%d examples with label size %d and %d blocks\n",
			num, labelsize, X.numblocks);
		printf("block size, regularization multiplier, learning rate multiplier\n");
		dim = 0;
		for (int i = 0; i < X.numblocks; i++) {
			dim += X.blocksizes[i];
			printf("%d, %.2f, %.2f\n", X.blocksizes[i], X.regmult[i], X.learnmult[i]);
		}

		// read component info file
		// format: #components {#blocks blk1 ... blk#blocks}^#components
		f = fopen(cmpfile, "rb");
		count = fread(&X.numcomponents, sizeof(int), 1, f);
		check(count == 1);
		printf("the model has %d components\n", X.numcomponents);
		X.componentblocks = (int **)malloc(X.numcomponents*sizeof(int *));
		X.componentsizes = (int *)malloc(X.numcomponents*sizeof(int));
		for (int i = 0; i < X.numcomponents; i++) {
			count = fread(&X.componentsizes[i], sizeof(int), 1, f);
			check(count == 1);
			printf("component %d has %d blocks:", i, X.componentsizes[i]);
			X.componentblocks[i] = (int *)malloc(X.componentsizes[i] * sizeof(int));
			count = fread(X.componentblocks[i], sizeof(int), X.componentsizes[i], f);
			check(count == X.componentsizes[i]);
			for (int j = 0; j < X.componentsizes[i]; j++)
				printf(" %d", X.componentblocks[i][j]);
			printf("\n");
		}
		fclose(f);

		// read examples
		f = fopen(datfile, "rb");
		check(f != NULL);
		printf("Reading examples\n");
		char **examples = (char **)malloc(num*sizeof(char *));
		check(examples != NULL);
		for (int i = 0; i < num; i++) {
			// we use an extra byte in the end of each example to mark unique
			// we use an extra int at the start of each example to store the
			// example's byte length (excluding unique flag and this int)
			//int buf[labelsize+2];
			int *buf = new int[labelsize + 2];

			count = fread(buf, sizeof(int), labelsize + 2, f);
			check(count == labelsize + 2);
			// byte length of an example's data segment
			int len = sizeof(int)*(labelsize + 2) + sizeof(float)*buf[labelsize + 1];
			// memory for data, an initial integer, and a final byte
			examples[i] = (char *)malloc(sizeof(int) + len + 1);
			check(examples[i] != NULL);
			// set data segment's byte length
			((int *)examples[i])[0] = len;
			// set the unique flag to zero
			examples[i][sizeof(int) + len] = 0;
			// copy label data into example
			for (int j = 0; j < labelsize + 2; j++)
				((int *)examples[i])[j + 1] = buf[j];
			// read the rest of the data segment into the example
			count = fread(examples[i] + sizeof(int)*(labelsize + 3), 1,
				len - sizeof(int)*(labelsize + 2), f);
			check(count == len - sizeof(int)*(labelsize + 2));

			delete[] buf;
		}
		fclose(f);
		printf("done\n");

		// sort
		printf("Sorting examples\n");
		char **sorted = (char **)malloc(num*sizeof(char *));
		check(sorted != NULL);
		memcpy(sorted, examples, num*sizeof(char *));
		qsort(sorted, num, sizeof(char *), comp);
		printf("done\n");

		// find unique examples
		int i = 0;
		int len = *((int *)sorted[0]);
		sorted[0][sizeof(int) + len] = 1;
		for (int j = 1; j < num; j++) {
			int alen = *((int *)sorted[i]);
			int blen = *((int *)sorted[j]);
			if (alen != blen ||
				memcmp(sorted[i] + sizeof(int), sorted[j] + sizeof(int), alen)) {
				i++;
				sorted[i] = sorted[j];
				sorted[i][sizeof(int) + blen] = 1;
			}
		}
		int num_unique = i + 1;
		printf("%d unique examples\n", num_unique);

		// collapse examples
		collapse(&X, sorted, num_unique);
		printf("%d collapsed examples\n", X.num);

		// initial model
		double **w = (double **)malloc(sizeof(double *)*X.numblocks);
		check(w != NULL);
		f = fopen(modfile, "rb");
		for (int i = 0; i < X.numblocks; i++) {
			w[i] = (double *)malloc(sizeof(double)*X.blocksizes[i]);
			check(w[i] != NULL);
			count = fread(w[i], sizeof(double), X.blocksizes[i], f);
			check(count == X.blocksizes[i]);
		}
		fclose(f);

		// lower bounds
		double **lb = (double **)malloc(sizeof(double *)*X.numblocks);
		check(lb != NULL);
		f = fopen(lobfile, "rb");
		for (int i = 0; i < X.numblocks; i++) {
			lb[i] = (double *)malloc(sizeof(double)*X.blocksizes[i]);
			check(lb[i] != NULL);
			count = fread(lb[i], sizeof(double), X.blocksizes[i], f);
			check(count == X.blocksizes[i]);
		}
		fclose(f);

		// train
		printf("Training\n");
		gd(C, J, X, w, lb, logdir, logtag);
		printf("done\n");

		// save model
		printf("Saving model\n");
		f = fopen(modfile, "wb");
		check(f != NULL);
		for (int i = 0; i < X.numblocks; i++) {
			count = fwrite(w[i], sizeof(double), X.blocksizes[i], f);
			check(count == X.blocksizes[i]);
		}
		fclose(f);

		// score examples
		printf("Scoring\n");
		double *s = score(X, examples, num, w);

		// Write info file
		printf("Writing info file\n");
		f = fopen(inffile, "w");
		check(f != NULL);
		for (int i = 0; i < num; i++) {
			int len = ((int *)examples[i])[0];
			// label, score, unique flag
			count = fprintf(f, "%d\t%f\t%d\n", ((int *)examples[i])[1], s[i],
				(int)examples[i][sizeof(int) + len]);
			check(count > 0);
		}
		fclose(f);

		// compute loss and write it to a file
		double lossinfo[3];
		compute_loss(lossinfo, C, J, X, w);
		printf("Writing objective function info file\n");
		f = fopen(objfile, "w");
		count = fprintf(f, "%f\t%f\t%f", lossinfo[0], lossinfo[1], lossinfo[2]);
		check(count > 0);
		fclose(f);

		printf("Freeing memory\n");
		for (int i = 0; i < X.numblocks; i++) {
			free(w[i]);
			free(lb[i]);
		}
		free(w);
		free(lb);
		free(s);
		for (int i = 0; i < num; i++)
			free(examples[i]);
		free(examples);
		free(sorted);
		free(X.x);
		free(X.blocksizes);
		free(X.regmult);
		free(X.learnmult);
		for (int i = 0; i < X.numcomponents; i++)
			free(X.componentblocks[i]);
		free(X.componentblocks);
		free(X.componentsizes);

		return 0;
	}

   - 下载svm_mex601工具包到voc-release4.01文件夹中

   - 修改global.m配置路径，注释掉判断文件夹是否存在的代码，配置结果路径，暂存数据路径和PASCAL VOC development kit and dataset

### LINK
1、[http://blog.csdn.net/dreamd1987/article/details/7399151](http://blog.csdn.net/dreamd1987/article/details/7399151 "train 移植1") train 移植1

2、[http://blog.csdn.net/pozen/article/details/7103412](http://blog.csdn.net/pozen/article/details/7103412 "train 移植2") train 移植2

3、[http://blog.sina.com.cn/s/blog_4af4d81f0101dk3u.html](http://blog.sina.com.cn/s/blog_4af4d81f0101dk3u.html "train 移植3") train 移植3

4、[http://blog.sina.com.cn/s/blog_4af4d81f0101dk38.html](http://blog.sina.com.cn/s/blog_4af4d81f0101dk38.html "detect 移植1") detect 移植1

5、[http://www.tuicool.com/articles/UreMvm](http://www.tuicool.com/articles/UreMvm "完整移植") 完整移植

6、[https://sourceforge.net/projects/mex-svm/files/Source/](https://sourceforge.net/projects/mex-svm/files/Source/ "svm_mex601 工具包") svm_mex601 工具包下载

7、[http://host.robots.ox.ac.uk/pascal/VOC/voc2007/index.html](http://host.robots.ox.ac.uk/pascal/VOC/voc2007/index.html "PASCAL VOC2007") PASCAL VOC2007 数据集和工具包

8、[http://people.eecs.berkeley.edu/~rbg/latent/index.html](http://people.eecs.berkeley.edu/~rbg/latent/index.html "DPM source code")  DPM source code
<file_sep>/windows-caffeAndFast-rcnn env/windows下的caffe和fast-rcnn环境配置.md
#Windows 下编译Caffe-window#

来源：[http://blog.csdn.net/happynear/article/details/45372231](http://blog.csdn.net/happynear/article/details/45372231)

##准备##
 1.从caffe-window官方fork过来的源码([https://github.com/happynear/caffe-windows](https://github.com/happynear/caffe-windows))下载，第三方库下载([http://pan.baidu.com/s/1nvH7whz](http://pan.baidu.com/s/1nvH7whz))

 2.在caffe源码根目录下建立一个3rdparty文件夹，将第三方库解压进去。然后把3rdparty/bin文件夹添加到环境变量中，方便程序查找第三方库。

 3.如果用GPU的话还需要考虑CUDA的安装。

##编译##

 1.点击./src/caffe/proto/extract_proto.bat批处理文件生成三个文件。

 2.使用GPU的话就打开./buildVS2013/MainBuilder.sln,否则打开./build_cpu_only/MainBuilder.sln来进行编译。注意将编译模式切换成Release X64模式。

	1、用matlab wrapper来提取特征、观察训练好的权重的话呢，只需要把matcaffe项目里面的matlab目录修改成你自
	己的，然后编译，你就能从matlab/+caffe/private文件夹里面找到一个叫caffe_.mexw64的文件。
	2、python的wrapper类似，把pycaffe项目里的python目录改成你自己的（我用的是Anaconda），就能在python/caffe
    文件夹中生成_caffe.pyd的python dll文件。
	python目录的修改的话，点击pycaffe项目->属性->配置属性->C/C++->常规->附加包含目录中和pycaffe项目->属
	性->配置属性->Linker->常规->附加包含目录中python的目录修改(使用Anaconda的话就是直接Anaconda根目录下
	的include，libs，Lib->site-packages)

##测试##

1.下载MNIST的leveldb数据文件，解压至./examples/mnist文件夹中。运行根目录下得run_mnist.bat,既可以开始训练(如果是使用CPU，注意将在mnist下得配置文件的选项改成CPU)。训练日志保存./log文件夹中(以INFO开头，txt格式的日志文件)。

#Windows 下编译fast-rcnn#

参考地址：[http://blog.csdn.net/happynear/article/details/46822109](http://blog.csdn.net/happynear/article/details/46822109)
##准备工作##

1、caffe-windows下载和编译，可以先编译python接口，剩下部分可后面再编译。

2、fast-rcnn:[https://github.com/rbgirshick/fast-rcnn。](https://github.com/rbgirshick/fast-rcnn。)

3、模型文件：原始文件在伯克利的服务器上，也可以到http://pan.baidu.com/s/1kTzQYgR下载，放在fast_rcnn根目录下的data文件夹（`fast_rcnn_root/data`）

4、安装protobu的python接口。google上下载protobuf-2.5.0.zip(源码)和protoc-2.5.0-win32.zip(win32)，源码用于安装环境，win exe 可以直接编译proto文件，将protoc-2.5.0-win32.zip中的protoc.exe放置在protobuf-2.5.0.zip解压出来的`protobuf-2.5.0\src`下。在cmd下切换目录到`protobuf-2.5.0\python`下，执行

	python setup.py build
	python setup.py test
	python setup.py install

成功运行三个命令。

（提前安装Anaconda或python）

5、在cmd中，输入`pip install cython`和`pip install easydict`来安装cython和easydict（Anaconda默认安装了cython），安装失败可能pip版本过低，先输入`pip install pip --upgrade` 升级 pip。

##编译工作##

1、将之前caffe-windows编译出来的python接口文件，即复制`caffe_windows_root/python`目录，复制到 `fast_rcnn_root/caffe-fast-rcnn`。

2、用文本打开`fast_rcnn_root/lib/utils/nms.pyx`，将第25行的`np.int_t`修改为`np.intp_t`，
如果没有修改NMS函数会出现类型不搭配，在后面的测试时。

3、用文本打开`fast_rcnn_root/lib/setup.py`,将第18行和23行的`-Wno-cpp`, `-Wno-unused-function`指令删除，只留下空的中括号[]即可。

4、打开cmd，定位至`fast_rcnn_root/lib`目录中，执行`python setup.py install`。

	Unable to find vcvarsall.bat 问题
	如果是安装protobu3.0.0的话，可能仅仅支持VS2015。
	解决方法的话：在CMD中输入
	VS2013:SET VS90COMNTOOLS=%VS120COMNTOOLS%
参考网站：[http://my.oschina.net/soarwilldo/blog/496463](http://my.oschina.net/soarwilldo/blog/496463)

setup.py安装完成后，到`python_root/Lib/site-packages/utils`中可以找到两个文件`cython_bbox.pyd`和`cython_nms.pyd`，把这两个文件复制到`fast_rcnn_root/lib/utils`中。

5、定位至`fast_rcnn_root`，执行`python tools/demo.py`

	%%如果仅仅使用CPU，需要demo.py中修改
    if 1:
        caffe.set_mode_cpu()（使用CPU）
    else:
        caffe.set_mode_gpu()
        caffe.set_device(args.gpu_id)（使用GPU）

![Alt Text](result.png)<file_sep>/ENVI/ENVI error.md
FLAASH 大气校正 error

![Alt Text](https://github.com/williamGD/Notes/blob/master/Pictures/FLAASHerror1.png)

原因分析：软件对输出/输入文件读写权限受限，如这里默认输出文件夹"C:\Users\dsbin\AppData\Local\Temp"读写权限受限，导致读取不到相应的文件

解决方案：更改默认输出文件夹<file_sep>/VSprofile/VS代码分析工具.md
##Visual Studio 代码分析##

If you need to simplily analyze your code, you could use the Analyze of VS.

1、ANALYZE->Peformance and Diagnostics.

![Alt text](1.png)

2、Select Performance Wizard and start.

![Alt text](2.png)

3、Select CPU sampling，One or more available project and Lauch. Waiting for the program end.

![Alt text](3.png)
![Alt text](4.png)
![Alt text](5.png)

4、ANALYZE YOUR CODE

![Alt text](6.png)
![Alt text](7.png)<file_sep>/TBB/INTEL_THREADING_BUILDING_BLOCKS.md
##四种主要多核并行编程方法分析与比较 #

1、Message Passing Interface(MPI)

>suport:C/C++/Fortran

>优点：可以在集群上使用，也可以在单核/多核CPU上使用，它能协调多台主机间的并行计算，因此并行规模上的可伸缩性很强，能在从个人电脑到世界TOP10的超级计算机上使用。

>缺点：第一，基于消息传递，需要显示划分和分布计算任务，显示进行消息传递与同步，且不易增量开发串行程序的并行性；第二，使用进程间通信的方式协调并行计算，这导致并行效率较低、内存开销大、不直观、编程麻烦。

2、Open Multi Processing(OpenMP)

>suport:C/C++/Fortran

>优点：第一，共享存储模型，使得程序员不必进行数据划分和分布，使得开发并行程序比较容易；第二，更适合于SMP系统；第三，主要面向循环级的并行开发，可以容易地实现增量性的并行化。

>缺点：第一，OpenMP只适用于SMP结构；第二，OpenMP主要开发循环级的并行程序，受此限制，对某些应用并不适合；第三，OpenMP的编写、正确性调试和性能调度复杂。

3、Integrated Performance Primitives(Intel IPP)

Intel集成性能基元是Intel函数库的第二代。Intel为每种新的多核处理器都发布一个IPP函数库（C/C++ API），专用于多核架构，提供了调度优化的函数库，其中涉及的领域有数学、信号处理、音频视频、图像处理与编码、字符串、密码学。

>suport:C/C++

>　　优点：是经过性能高度优化的库，执行效率高。

>　　缺点：专用于Intel处理器和某些领域，不方便移植。

4、Threading Building Blocks(Intel TBB)

>suport:C/C++

>　　优点：可移植、可扩展。

>　　缺点：性能没有IPP高。

## Intel Threading Building Blocks(TBB)##

INTRODUCE：多核处理器的C++库，线程级的并行

>TBB 提供的接口：由底层到高层

>task_scheduler----->concurrent_container----->parallel_for----->pipeline

1、并发容器（concurrent_container）

大部分程序都有容器类，在多线程环境下就有数据污染的问题，为了使并发的线程串行化，一般是使用加锁的办法，如果这个
容器由程序员自己来实现，难度还是比较大的，这样就需要有线程安全的容器类。

1、concurrent_hash_map

hash接口与stl类似

2、concurrent_vector

grow_by(n) 插入n个item（动态增长）

grow_to_at_least（）设定容器的大小

size()  包括正在并发增长的部分 因为有可能会同时取，所以程序员需要自己维护自己的class的线程安全性

clear() 不是线程安全的

3、concurrent_queue

pop_if_present(item) 非阻塞，

pop（） 阻塞，

concurrent_queue::size() 负数时表示有多少个消费者在等待

set_capacity（）指定队列大小，会使push操作被阻塞

在并行时，paralell_while pipeline 的效率要高于concurrent_queue

2、parallel

| function         |parallel_for      |parallel_reduce    |parallel_while   |
| ----------------:| ----------------:| ----------------:| ----------------:|
| Introduction     | 多个数据或请求没有依赖关系，所要进行的操作是一样的|适合于需要汇总的情况，例各个数据的结果需要汇总回来|不知道循环何时结束，例使用for的end未知|

**Link(download)**:[https://www.threadingbuildingblocks.org/download#development-releases](https://www.threadingbuildingblocks.org/download#development-releases)

安装

- 下载：windows release版tbb
- 配置环境变量PATH，保证运行时找到dll
- 在TBB应用工程中添加tbb包含目录，即tbb相关头文件
- 在TBB应用工程中添加tbb库目录，即tbb的lib文件，注意32位和64位有分别的目录<file_sep>/DLAndNN/神经网络与深度学习_吴岸城.md
## 神经网络和深度学习 ##

### Note1 ###

**单个神经元**

**传递函数**：

常用的：阶梯函数（step），符号函数（sgn），线性函数（Linear），饱和线性函数（Ramp），对数S型函数（Sigmoid），双曲正切S型函数（Tanh）。

**感知机**：

感知机是最简单的神经网络。

>Neuroph:基于Java的神经网络框架

感知机无法解决XOR问题（可以解决AND和OR问题）。

>线性不可分是导致不能解决XOR问题的原因，而AND和OR则是线性可分的问题

**多层神经网络**

XOR问题可以通过在单层神经网络多加一层，并且利用Back-Propagating（BP）算法来解决。

1、感知器

双层神经网络模型，输入层和计算单元。

2、多层神经网络（前馈神经网络）

3、计算单元

任意输入，单一输出。

4、层

### Note2 ###

  - 监督学习
  - 非监督学习
  - 强化学习（Reinforcement Learning）
  回报函数，无label，本质是马尔科夫决策过程，最终目的是决策过程中整体回报函数期望最优	。

深度学习是神经网络的一大分支，深度学习的基本结构是深度神经网络。

**特征**

人类视觉系统提取的过程是由：Retina->V1->V2->V4，高级表达是由低级表达组成的。

1、特征粒度

2、浅层特征

复杂图形是由基本图形构件组成。类似基

3、结构性特征

Retina->像素(pixls)

V1->边缘(edges)

V2->构件(object parts)

V4->物体(object models)

**浅层学习和深层学习**

浅层学习：多层感知机，SVM，Boosting，Logistics Regression
。单个隐层或没有隐层。

深层学习：多个隐层。Hinton提出的（Deep Belief Network）DBN
划时代。其中重要的几个原则

>  - 非监督学习被用来预训练各个层
>  - 非监督学习在之前学习到的层次之上，一次只学习一个层次，每个层次学习的结果作为下一个层次的输入
>  - 用监督学习来调整层之间的权重。

**深度学习和神经网络**

>BP算法：神经网络的训练

>    - 信号正向传播
>    - 误差反向传播

问题在于梯度稀疏，误差校正越来越小从顶至下；收敛局部最小值。

### Note3 ###

**深度学习常用方法**

自编码器

有监督微调：只调整最后的分类器；调整整个系统。

栈式自编码器：提供预训练方法初始化网络权重。

限制玻尔兹曼机

1、生成模型和概率模型

   - 决策函数\\(Y=f(X)\\)和条件概率分布\\(P(Y/X)\\)可以互相转化。决策函数在分类器设计时就需要估计根据给定的训练数据进行估计概率模型。但是概率分布模型往往难以估计，所以我们转而从训练样本和问题出发来求出判别函数，也就是决策函数。这就包括了SVM是求出分类面，近邻法是求出预测数据通训练数据比较，取最近相同分类。

   - 生成方法(Generative Approach)和判别方法(Discriminative Approach),生成模型可以推出判别模型，反之不然。生成可以找到数据分布情况，反应同类数据本身相似度，但求不出边界。而判别式可以求出最有分类面。生成学习\\(p(x,y)\\),判别学习\\(p(y|x)\\)。\\(p(y|x)=p(x,y)/p(x)\\)

   - 能量模型。将求稳态转换成求极值优化问题。任何概率分布都可以转化成基于能量模型。系统有序或者概率分布越集中，系统能量越小，反之越大。能量模型提出就是求系统的稳态，也就是能量最小值。

2、RBM

RBM包括可见层，隐层和偏置层。可见层和隐层链接方向不确定，可以双向传播，完全连接的。

RBM几个参数有权重矩阵，可视层和隐层分别的偏置量。

用来：降维；初始化神经网络初始值；求联合概率；求条件概率。

3、DBN（Deep Belief Network）深度信念网络

RBM堆叠起来的DBN。用逐层贪婪训练方法（Greedy Layer-wise Training）。非监督单层，BP网络监督训练。

4、CNN卷积神经网络

结构：Convolution Layer 和 Subsample Layer（Pooling Layer）。

权值共享和参数减少。

5、RNN（循环神经网络），非递归神经网络，也叫RNN

LSTM典型的循环神经网络。

<file_sep>/Opt/ALM和LM.md
ALM(增广拉格朗日乘子)与LM(拉格朗日乘子)

目标函数不同：

拉格朗日乘子法的目标函数是：
$$
P(x,\lambda)=f(x)-\lambda*g(x)
$$

增广拉格朗日乘子法的目标函数是:

$$
P(x,\lambda,r)=f(x)-\lambda*g(x)+ r/2 *g(x)^{2}
$$

![Alt Text](../Pictures/ALM.png)<file_sep>/Tips/Tips2.md
##Tips Matlab 矩阵优化性能问题##

>MATLAB的矩阵计算使用的是Intel自己出的Math kernel library（MKL）,这个库远比其他的blas/lapack库要快。

>C/C++快在循环,优化连接MKL，编写难比专业优化

>Python的NumPy矩阵运算仅仅是接近Matlab，但是在其他方面比Matlab有较好的性能。

常见的BLAS库的矩阵运算性能

1. EIGEN
Eigen 是一个线性算术的C++模板库。功能强大、快速、优雅以及支持多平台，可以使用该库来方便处理一些矩阵的操作，达到类似matlab那样的快捷。 需要定义 EIGEN_NO_DEBUG 阻止运行时assertion。编译单线程版本需要开启 -DEIGEN_DONT_PARALLELIZE.
2. Intel MKL
英特尔数学核心函数库是一套经过高度优化和广泛线程化的数学例程，专为需要极致性能的科学、工程及金融等领域的应用而设计。它可以为当前及下一代英特尔处理器提供性能优化，包括更出色地与 Microsoft Visual Studio、Eclipse和XCode相集成。英特尔 MKL 支持完全集成英特尔兼容性 OpenMP 运行时库，以实现更出色的 Windows/Linux 跨平台兼容性。在试验中的多线程版本需要链接到 mkl_gnu_thread，而不是 mkl_intel_thread，单线程版本需要链接到 mkl_sequential_thread。
3. OpenBLAS
OpenBLAS是高性能多核BLAS库，是GotoBLAS2 1.13 BSD版本的衍生版。OpenBLAS 的编译依赖系统环境，并且没有原生单线程版本，在实验这哦那个，通过设置 OMP_NUM_THREADS=1 来模拟单线程版本，可能会带来一点点的性能下降。

整体看，在单线程和多线程下，OpenBLAS最好，MKL次之，EIGEN最末

##Tips 浮点到定点转换##

### 简介 ###
采用定点数进行数值运算，其操作数一般采用整型数来表示。一个整型数的最大表示范围取决于运算芯片所给定的字长，一般为16位或24位。显然，字长越长，所能表示的数的范围越大，精度也越高。如无特别说明，本文均以16位字长为例。参与运算的数以二进制补码形式表示。每个16位数用一个符号位来表示数的正负，0表示数值为正，1则表示数值为负。其余15位表示数值的大小。

### 定点表示 ###

参与数值运算的数为16位的整型数。但在许多情况下，数学运算过程中的数不一定都是整数。应该说，运算芯片本身无法处理小数。关键就是由程序员来确定一个数的小数点处于16位中的哪一位。这就是数的定标。｛通过设定小数点在16位数中的不同位置，就可以表示不同大小和不同精度的小数｝数的定标有Q表示法和S表示法两种。下面列出了一个16位数的16种Q表示、S表示及它们所能表示的十进制数值范围：

浮点数转换为定点数时,为了降低截尾误差,可以在取整前可以先加上0.5，视情况而定。

![Alt Text](定点浮点.png)

![Alt Text](Q表示.png)

### 定点加减法 ###

将浮点加法/减法转化为定点加法/减法时最重要的一点就是必须保证两个操作数的定标值一样。若两者不一样，则在做加法/减法运算前先进行小数点的调整。为保证运算精度，需使Q值小的数调整为与另一个数的Q值一样大。此外，在做加法/减法运算时，必须注意结果可能会超过16位表示。如果加法/减法的结果超出16位的表示范围，则必须保留32位结果，以保证运算的精度。

    // 设x的Q值为Qx，y的Q值为Qy，且Qx > Qy，加法/减法结果z的定标值为Qz
    // 所以定点加法可以描述为：
    int x,y,z;
    long temp; // 临时变量
    temp = y << (Qx - Qy);
    // Q大-Q小，Q大的变量分辨率更高，Q小的左移增加其Q
    temp = x + temp;
    z = (int)(temp >> (Qx - Qz)); // if Qx >= Qz
    z = (int)(temp << (Qz - Qx)); // if Qx <= Qz

E.g.

	// 设x = 0.5，y = 3.1，则浮点运算结果为z = x+y = 0.5+3.1 = 3.6;
	// Qx = 15，Qy = 13，Qz = 13，则定点加法为：
	x = 16384；y = 25395;
	temp = 25395 << 2 = 101580;
	temp = x+temp = 16384+101580 = 117964;
	z = (int)(117964L >> 2) = 29491;
	// 因为z的Q值为13，所以定点值z = 29491即为浮点值z = 29491/8192 = 3.6。

### 定点乘法 ###

    int x,y,z;
    long temp;
    temp = (long)x;
    z = (temp×y) >>(Qx+Qy-Qz);

E.g.

	// 设x = 18.4，y = 36.8，则浮点运算值为z = 18.4×36.8 = 677.12;
	// 根据上节，得Qx = 10，Qy = 9，Qz = 5，所以
	x = 18841；y = 18841;
	temp = 18841L; // Long int
	z = (18841L * 18841) >> (10+9-5) = 354983281L >> 14 = 21666;
	// 因为z的定标值为5，故定点 z = 21666即为浮点的 z = 21666/32 = 677.08 产生了精度损失

### 定点除法 ###

	int x,y,z;
	long temp;
	temp = (long)x;
	z = (temp<<(Qz-Qx+Qy))/y ;

E.g.

	//设x = 18.4，y = 36.8，浮点运算值为z = x/y = 18.4/36.8 = 0.5;
	//根据上节，得Qx = 10，Qy = 9，Qz = 15；所以有
	x = 18841, y = 18841;
	temp = (long)18841;
	z = (18841L<<(15-10+9))/18841= 308690944L/18841 = 16384;
	//因为商z的定标值为15，所以定点z = 16384即为浮点 z = 16384/215= 0.5。

### 非线性运算定点的快速实现 ###

在数值运算中，除基本的加减乘除运算外，还有其他许多非线性运算，如对数运算、开方运算、指数运算、三角函数运算等，实现这些非线性运算的方法一般有：(1)调用DSP编译系统的库函数；(2)查表法；(3)混合法。主要介绍查表法

1．调用DSP编译系统的库函数

略

2.查表法

在实时DSP应用中实现非线性运算，一般都采取适当降低运算精度来提高程序的运算速度。查表法是快速实现非线性运算最常用的方法。采用这种方法必须根据自变量的范围和精度要求制作一张表格。显然输入的范围越大，精度要求越高，则所需的表格就越大，即存储量也越大。**查表法求值所需的计算就是根据输入值确定表的地址，根据地址就可得到相应的值，因而运算量较小。查表法比较适合于非线性函数是周期函数或已知非线性函数输入值范围这两种情况。**

例3.12  已知正弦函数y=sin(x)，制作一个512点表格，并说明查表方法。由于正弦函数是周期函数，函数值在－1至＋1之间，用查表法比较合适。由于Q15的表示范围为－1至32767/32768之间，原则上讲－1至＋1的范围必须用Q14表示。但一般从方便和总体精度考虑，类似情况仍用Q15表示，此时＋1用32767来表示。

(1)   建立正弦函数y=sin(x)值表。
Q=15时，产生512点正弦值的数学公式：i ——为index，Q ——为定标值，即产生512点值的C语言程序如下所示:

	/* Sample 3.12: Generate a sinewave table
	 * Q = 15
	 * N is the number of points
	 * i is the index of each value, 0:N
	 * float multiply and integerize.
	 */

	#define  N  512
	#define  pi  3.14159
	int  sin_tab[512];
	void  main()
	{
	  int i;
	  for(i=0;i<N;i++)
	      sin_tab[i]=(int)(32767*sin(2*pi*i/N));//32767 = 2^15 - 1
	}

(2) 查表

查表实际上就是根据输入值确定表的地址。设输入浮点x在0~2p之间，则x对应于512点表的地址为：index = (int)(512*x/2p)
则：y = sin(x) = sin_tab[index]

如果此处把x用定点数表示，则取x的Q值为15-3=12. 因为0<x<6.29<8=2^3, 取Q=15-3可以最大限度保证x精度。将512/2p≈81.53. 2^6<81.53< 2^7=128用Q8（15 –7 = 8）表示才能将其囊括，其在Q8下的值为 (int)(81.53*2^8) = 20871，则计算正弦值表的地址的公式为：index = (x*20871L)>>20。此处index的类型本来就是int，且范围是[0:1:512]，故它的Q值为零。所以是右移 12+8-0=20位，得到0-512的index值。

	The whole program for generating sine wave table and usingit to get the sin value:
	/* Sample 3.12: Generate a sinewave table
	 * Q = 15
	 * N is the number of points
	 * i is the index of each value, 0:N
	 * float multiply and intigerize.
	 */

	#include "stdafx.h"  // Thisis for visual studio C++
	#include "stdio.h"
	#include "math.h"
	#include "string.h"
	#define  pi  3.14159

	/* Generate and inject the n point sine wave table Function
	 * Sine wave value is from -1 to +1,Select Q=15: [-1,0.9999695], 16bit int
	 * input the sin_table arraydeclared in main function
	 * Generate the sine value andmemcpy them into sin_table array
	 * Generate the fixed point valuefor sine wave. 32767 stands for 1.
	 * The fixed point sine value isfrom -32768 to 32767
	 *
	 */

	void usr_sineOcp(intshort sin_tab[],int n);//Declare sine wave table Function
	/* Generate the n-point(n<4096) sine wave table Function Body*/
	void usr_sineOcp(intshortsin_tab[],int n){
	  int short y[4096];// n < 4096
	  int i;
	  for(i=0;i<n;i++) {
	      y[i]=(int)(32767*sin(2*pi*i/n));  //32767 = 2^15 - 1
	      //printf("usr_sineOcp: y[%d] =%d \n", i, y[i]);
	  }
	  memcpy(sin_tab, y, 2*n);
	  return;
	}

	/* In main function, We will
	 * 1. Generate the empty sine_wavevalue table, 512points.
	 * 2. Occupy the sine_wave valuetable by calling usr_sineOcp(); function
	 * 3. print out the fixed/floatvalue of sine_wave value table.
	 * 4. Request user input float x,return float y.
	 *   float x_user_input = [0,2pi]
	 *   float y_ret_user = [-1, 0.9999695]
	 *
	 */

	void  main() // mainfunction
	{
	  int n=512;
	  int short sine_tab[512];  // Declare a 512 points sinusoid value table
	  int i;                     // index of this table

	  //2. Occupy the sine_wave value tableby calling usr_sineOcp(); function
	  usr_sineOcp(sine_tab, 512);

	  //3. print out the fixed/float valueof sine_wave value table.
	  for(i = 0; i < 512; i++)
	      printf("main: sine_tab[%d] = %d\n", i,sine_tab[i]);

	  //4. Request user input float x,return float y.
	  //  Using the sine_tab to get the y_fixed and transfer it into y_float
	  float x_f,y_f;
	  int short x,y,index;  //  x is Q12 fixed, index is []
	  int long x1;   // x1 is Q8 fixed but long inttype
	  printf("Please Enter a x_float (rad)value (0:2pi): ");//? howto extend??
	  scanf("%f", &x_f);
	  // Figure out the index for checkingsine_tab table
	  x = (int) (x_f*4096);   // x_fixed = x_f * (2^12) , Qx = 12
	  x1 = 20871;            // x1L = 20871 = 512/2PI * 2^8, Qx1 = 8
	  index = (x*x1) >> 20;  //get the index for sin table
      printf("x Q12 fixed[0-25740] = %d\n",x);
      printf("index [0-512] =%d \n",index);
      // Use index to check the sinusoidvalue:
	  y = sine_tab[index];
	  printf("The fixed y(-32768,32767) is:%d \n",y);

	  // Transfer y_fixed intoy_float[-1,+1]

	  y_f = ((float)y) / 32768;

	      printf("The float y_f(-1,+1) is: %f \n", y_f);

	}

例3.13  用查表法求以2为底的对数，已知自变量取值范围为0.5~1,要求将自变量范围均匀划分为10等分。试制作这个表格并说明查表方法。

(1) 做表：

y = log2(x)，由于x在0.5到1之间，因此y在-1到0之间，x和y均可用Q15表示。由于对x均匀划分为10段，因此，10段对应于输入x的范围如表3.2所示。若每一段的对数值都取第1点的对数值，则表中第1段的对数值为y0(Q15) = (int)(log2(0.5)×32768)，第2段的对数值为y1(Q15) = (int)(log2(0.55)×32768)，依次类推。

(2) 查表:

查表时，先根据输入值计算表的地址，计算方法为：index=((x-16384)×20)>>15。式中，index就是查表用的地址。例如，已知输入x= 26869，则index=6，因此y=-10549。

3.混合法

(1) 提高查表法的精度

上述方法查表所得结果的精度随表的大小而变化，表越大，则精度越高，但存储量也越大。当系统的存储量有限而精度要求也较高时，查表法就不太适合。那么能否在适当增加运算量的情况下提高非线性运算的精度呢？下面介绍一种查表结合少量运算来计算非线性函数的混合法，这种方法适用于在输入变量的范围内函数呈单调变化的情形。

混合法是在查表的基础上采用计算的方法以提高当输入值处于表格两点之间时的精度。提高精度的一个简便方法是采用折线近似法，如图3.1所示。

仍以求以2为底的对数为例(例3.13)。设输入值为x，则精确的对数值为y，在表格值的两点之间作一直线，用y＇作为y的近似值，则有：y＇＝y0＋y其中y0由查表求得。现在只需在查表求得y0的基础上增加y即可。y的计算方法如下：

y=(x/x0)y=x(y0/x0)式中y0/x0对每一段来说是一个恒定值，可作一个表格直接查得。此外计算x时需用到每段横坐标的起始值，这个值也可作一个表格。这样共有三个大小均为10的表格，分别为存储每段起点对数值的表logtab0、存储每段y0/x0 值的表logtab1和存储每段输入起始值x0的表logtab2，表logtab1和表logtab2可用下列两个数组表示：

	int    logtab1[10]={22529,20567,18920,17517,16308,
	            15255,14330,13511,12780,12124};  /*y0/x0 : Q13*/
	int    logtab2[10]={16384,18022,19660,21299,22938,
	            24576,26214,27853,29491,31130};  /* x0: Q15*/

综上所述，采用混合法计算对数值的方法可归纳为：

①根据输入值，计算查表地址：index=((x-16384)×20)>>15;

②查表得y0=logtab0[index];

③计算x=x-logtab2[index];

④计算y＝(x×logtab1[index])>>13;

⑤计算得结果y=y0+y。

例3.14  已知x=0.54，求log2(x)。

0.54的精确对数值为y=log2(0.54)=-0.889。

混合法求对数值的过程为：

①定标Q15，定标值x=0.54*32768=17694；

②表地址index=((x-16384)×20)>>15=0;

③查表得y0=logtab0[0]=-32768;

④计算x=x-logtab2[0]=17694-16384=1310;

⑤计算y＝(xlogtab1[0])>>13=(1310*22529L)>>13=3602;

⑥计算结果y=y0+y=-32768+3602=-29166。

结果y为Q15定标，折算成浮点数为-29166/32768=-0.89，可见精度较高。

(2) 扩大自变量范围

如上所述，查表法比较适用于周期函数或自变量的动态范围不是太大的情形。对于像对数这样的非线性函数，输入值和函数值的变化范围都很大。如果输入值的变化范围很大，则作表就比较困难。那么能否比较好地解决这个问题，既不使表格太大，又能得到比较高的精度呢？下面讨论一种切实可行的方法。

设x是一个大于0.5的数，则x可以表示为下列形式：

x =

式中，0.5≤m≤1.0，e为整数。则求 x 的对数可以表示为：

log2(x) = log2() = log2(m) + log2() = e + log2(m)

也就是说，求x的对数实际上只要求 m的对数就可以了，而由于m的数值在0.5~1.0之间，用上面介绍的方法是完全可以实现的。例如：

log2(10000) = log2(0.61035×) = log2(0.61035) + 14 = 13.2877

可见，如果一个数可以用比较简便的方法表示为上面的形式，则求任意大小数的对数也是比较方便的。TMS320C2X/C5X指令集提供了一条用于对ACC中的数进行规格化的指令NORM ，该指令的作用就是使累加器中的数左移，直至数的最高位被移至累加器的第30位。例如，对数值10000进行规格化的TMS320C25程序为：

	LAC      #10000
	SACL    TEMP
	ZALH    TEMP
	LAR      AR1,#0FH
	RPT       14
	NORM   *－

上述程序执行后，AR1=#0eH，ACCH=2000(10进制)。对一个16位整数 x 进行上述程序处理实际上就是做这样一个等效变换：

x =

其中，寄存器AR1包含的值为15-Q，累加器ACC高16位包含的值为，其数值在16384~32768之间。

例3.15  实现以2为底的对数的C定点模拟程序

	int    logtab0[10]＝{-32768,-28262,-24149,-20365,-16862,
	            -13600,-10549,-7683,-4981,-2425}; /*Q15*/
	int    logtab1[10]＝{22529,20567,18920,17517,16308,
	           15255,14330,13511,12780,12124};  /*Q13*/
	int    logtab2[10]＝{16384,18022,19660,21299,22938,
	           24576,26214,27853,29491,31130};  /*Q15*/
	int    log2_fast(int   Am)
	{
		int     point,point1;
		int     index,x0,dx,dy,y;
		point＝0;
		while(Am<16384) {point++；Am＝Am<<1;} /*对Am进行规格化*/
		point1＝(15-point-4)*512;        /*输入为Q4，输出为Q9*/
		index＝((Am-16384)*20L)>>15;             /*求查表地址*/
		dx＝Am-logtab2[index];
		dy＝((long)dx*logtab1[index])>>13;
		y＝(dy+logtab0[index])>>6;              /*Q9*/
		y＝point1+y;
		return (y);
	}

上述程序中，输入值Am采用Q4表示，输出采用Q9表示，如果输入输出的Q值与上面程序中的不同，则应做相应的修改。

## RGB2LUV ##

### RGB → XYZ ###

![Alt text](RGB2XYZ1.png)

or

![Alt text](RGB2XYZ2.png)

### XYZ → CIELUV ###
![Alt text](XYZ2LUV1.png)

The quantities \\(u_n\\) and  \\(v_n\\) are the (\\(u^{′}, v^{′}\\)) chromaticity coordinates of a "specified white object".(For example, for the 2° observer and standard illuminant C, \\(u_n\\) = 0.2009, \\(v_n\\) = 0.4610.)

![Alt text](XYZ2LUV2.png)

## AVX and SSE ##

SSE的全称是 Sreaming SIMD Extensions， 它是一组CPU指令，用于像信号处理、科学计算或者3D图形计算一样的应用。最早在奔腾处理器上，现在已经进化到SSE4，已经可以在酷睿中使用了。

SIMD 也是几个单词的首写字母组成的： Single Instruction, Multiple Data。 一个指令发出后，同一时刻被放到不同的数据上执行，这个指令就是SIMD指令。

从SSE2开始支持任何基本的数据类型。

LINK(SSE Tutorial):

[http://neilkemp.us/src/sse_tutorial/sse_tutorial.html](http://neilkemp.us/src/sse_tutorial/sse_tutorial.html)

[https://msdn.microsoft.com/en-us/library/kcwz153a(v=vs.100).aspx](https://msdn.microsoft.com/en-us/library/kcwz153a(v=vs.100).aspx)<file_sep>/DPM/DPM原理.md
# Filter channels Features

><NAME>, <NAME>, and <NAME>. "Filtered feature channels for pedestrian detection." Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015.

# DPM

>Object detection with discriminatively trained partbased models. IEEE Trans. PAMI, 32(9):1627–1645, 2010.

## DPM feature
![Alt text](.\Improve_HOG_byDPM.jpg "DPM")

1、8x8 Cell单元的概念；

2、归一化同周围组成的区域进行归一化；

3、计算梯度使用无符号（0-180°）和有符号（0-360°）结合策略，如果全部计算会达到 4x(9+18)=108 的维度；

4、提取无符号梯度，完整的cell会有4x9=36 维特征，进行近似PCA降维，前11个基本包含所有信息，仅仅取前9维，然后对4x9=36的矩阵，进行列的求和得到9个无符号梯度特征。 提取有符号梯度则进行列累加，有18个特征。还有对有符号梯度进行行的累加，有4个特征。最终获得9+18+4=31维特征。

## DPM model

![Alt text](.\DPMpedestrainmodel1.png "rootmodel title")
![Alt text](.\DPMpedestrainmodel2.png "partmodel title")
![Alt text](.\DPMpedestrainmodel3.png "partmodel cost title")

根模型，部件模型以及部件偏离损失。

## DPM detection

![Alt text](.\DPMdetectionprocess.png "DPM detection")

单一尺度下的检测流程

- 某一位置(x,y)与根模型/部件模型的响应得分，为该模型与该位置为锚点(左上角坐标)的子窗口区域内特征的内积，响应为特征与待匹配模型的相似程度；

- 响应变换：以锚点为参考位置，综合部件模型与特征的匹配程度和部件模型相对理想位置的偏离损失，得到的最优的部件模型位置和响应得分；

- 部件模型分辨率是根模型分辨率的1倍，因此部件模型需要在尺度层进行匹配考虑，即将锚点放大一倍。

DPM 速度慢，改进过的加速的算法有

>30Hz Object Detection with DPM V5<file_sep>/Tips/Tip1.md
### Confusion Matrix

| Confusion Matrix |Predicted Positive|Predicted Negative|
| ----------------:| ----------------:| ----------------:|
| Actual Positive  | TP               | FN               |
| Actual Negtive   | FP               | TN               |

**1.Basic evaluation:**

TPR: ture positive rate:  TP/(TP+FN) (equal to recall)

FPR: false positive rate: FP/(FP+TN)

TNR: true negative rate:  TN/(TN+FP)

FNR: false negative rate: FN/(FN+TP)

**2.Other evaluation:**

Accuracy=(TP+TN)/(TP+FN+FP+TN)

Missing rate=1-TPR=FNR

>漏警率(Missing Alarm): 漏警率(Missing Alarm)=1-Recall=FN/(TP+FN) 等同于Missing rate

Pecision: P=TP/(TP+FP)

Recall  : R=TP/(TP+FN)

虚警率(False Alarm)  : 虚警率(False Alarm)=1-pecision=FP/(TP+FP)

### Pedestrain detection evaluation :FPPI and FPPW (benchmark)

><NAME>, et al. "Pedestrian detection: A benchmark." Computer Vision and Pattern Recognition, 2009. CVPR 2009. IEEE Conference on. IEEE, 2009

FPPW： Given a set of N **negative samples image**, FPPW=FP/N (equal to false positive rate), that specifies the number of incorrect detections (FP), from the set of thousands or millions of negative examples in the testing set (notice that FPPW is not a rate but an absolute value). **a image is a sample**

It could be called per-window test, the axes of this plot are miss rate (MR) and false positives per window (FPPW). The FPPW working range depends on the dataset, but it is usually between 10−1 to 10−6. Notice that the axes are usually plotted in a log–log scale in order to focus on smallMR and FPPW values.

FPPI：Given a set of N image, **which exist or not exist detection objections**, FPPI=FP/N. (overlap when predicted bounding box hit actual bounding box is key.)

In this case, label is TP if it overlaps more than 50% (overlap we could determine) an annotated pedestrian in the groundtruth. Otherwise not overlap would be labeled as FN. The range tends to be between 10^(-2) to 10^(-0).

**FPPI is better than FPPW.**

The typical curves for test are **receiver operating characteristic(ROC)**, detection-error-tradeoff(DET) and precision-recall

PR curve and missing rate VS FPPI would be as evaluation tools for perdestrain detection. There is a little different between them.

Almost pedestrain detection would use missing rate VS FPPI (ROC curve) as a evaluation.

#Using missing rate VS FPPI

## UDN and ContDeepNet (2014)
### 1、Unified deep net(UDN)

Dataset: Caltech and ETH

Evaluation tool: missing rate VS FPPI

**Best performace: average missing rate 39% in the Caltech-Test dataset.**

> Ouyang, Wanli, and <NAME>. "Joint deep learning for pedestrian detection." Proceedings of the IEEE International Conference on Computer Vision. 2013.

### 2、ContDeepNet

Dataset: Caltech, ETHZ and TUD-Brussels

Evaluation tool: missing rate VS FPPI

**Best performace: average missing rate 45% in the Caltech-Test dataset.**

><NAME>, <NAME>, and <NAME>. "Multi-stage contextual deep learning for pedestrian detection." Proceedings of the IEEE International Conference on Computer Vision. 2013.

#Using PR curve

## DPM (2014)

### Objection detection

Dataset: INRIA

Evaluation tool: PR-curve

**Best performace: average percision rate 37.6 for person class in INRIA**

>Felzenszwalb, <NAME>., <NAME>, and <NAME>. "Cascade object detection with deformable part models." Computer vision and pattern recognition (CVPR), 2010 IEEE conference on. IEEE, 2010.

### About Occluded people

>Tang, Siyu, <NAME>, and <NAME>. "Detection and tracking of occluded people." International Journal of Computer Vision 110.1 (2014): 58-69.

#Survey about pedestrain protection system(PPS)

>Gerónimo, David, and <NAME>. Vision-based pedestrian protection systems for intelligent vehicles. Springer, 2014.

##Candidates Generation

###2D-Based Approaches

Sliding windows in different scale(Could be input image or detection window, but scaling input image would be better than detection window, because the local image features in a resizing detection windowmust be also resizeable, while in the image-pyramid scanning they are not restricted.) depend on pedestrain modle size.

**Problem:**
This would generate hundreds of thousands to millions of windows, depend on the sampling step and the minimun window size.

**Solution:**

1.Reduce the top 1/3 of the image (could avoid perspective-incorrect candidates such as small-sized windows in near road positions.);

2.**flat world assumption** defines the techniques that restrict the candidate search to the ground plane without any other information than the initial camera position with respect to the plane.(could avoid urban scenes)

Somebody considers correcting the vertical image position by relying on the detection of horizontal edges oscillations depend on the previous frams to solve
this problem in urban scenes.

3.Using **implicit shape model(ISM)** classification technique, matching the ones in a pedestrian model vote to promising location in the image likely to contain pedestrians.

4.coarse-to-fine search

###3D-Based Approaches
...
###Motion-Based Approaches
Inter-frame motion and optical flow

##Classification
###Pedestrian Models
Holistic considers pedestrains as a whole.

parts-based methods  pedestrians consist of a set of body-inspired part, anatomy-based pr location-based, complemented with full body(holistic) as well.

parts-based methods could explicity incorporate multi-view, multi-resolution, and occlusion modeling.

###Pedestrian Classifiers

...
###Holistic Models:Focus on the Features

A hierachy would be used in  coarse-to-fine search to captures pedestrian silhouette.

**chamfer distance transform**
><NAME>. "Distance transformations in digital images." Computer vision, graphics, and image processing 34.3 (1986): 344-371.

**the implicit shape model (ISM)** Original Image->Keypoint detection(SIFT, Harris-Laplace and shape context)->Matched codebook->Probabilistic voting->Maxima Selection->Back projection of masks

>Leibe, Bastian, <NAME>, and <NAME>. "Combined object categorization and segmentation with an implicit shape model." Workshop on statistical learning in computer vision, ECCV. Vol. 2. No. 5. 2004.

>Leibe, Bastian, and <NAME>. "Interleaving object categorization and segmentation." Cognitive Vision Systems. Springer Berlin Heidelberg, 2006. 145-161.

Some Feature :Haar-like, LBP, HOG and so on.
<file_sep>/FastRCNN/FasterRCNN.md
# RCNN,Fast-RCNN and Faster-RCNN #

Reference：[http://blog.csdn.net/gavin__zhou/article/details/51996615](http://blog.csdn.net/gavin__zhou/article/details/51996615)

- `RCNN` 解决的是，“为什么不用`CNN`做classification呢？”
- `Fast-RCNN` 解决的是，“为什么不一起输出bounding box和label呢？”
- `Faster-RCNN` 解决的是，“为什么还要用selective search呢？”(Selective Search 费时)

`Faster-RCNN`原理简介

在如何产生`proposal`进行加速，由传统的`Selective Search`到用`Nerual Net`来做`region proposal`。

在Fast-rcnn的基础上共享卷积层。用卷积后的特征图来生成region proposals。通过增加两个卷积层来实现Region Proposal Networks (RPNs) , 一个用来将每个特征图 的位置编码成一个向量，另一个则是对每一个位置输出一个 objectness score 和 regressed bounds for k region proposals.

![Alt Text](FasterRCNN.jpg)

## RPN(Region proposal NetWorks) ##

RPN 作用：

- 输出proposal的位置(坐标)和score
- 将不同scale和ratio的proposal映射为低维的feature vector
- 输出是否是前景的classification和进行位置的regression

Anthor概念:不同ratio和scale下的box集合就是anchor。最后一层卷积下生成的n*n区域，进行不同ratio和scale的采样

![Alt Text](FasterRCNNAnchor.jpg)

## RPN cls and reg ##

RPN输出对于某个proposal，其是属于前景或者背景的概率(0 or 1)，具体的标准论文里给出的是:

- 和所有的ground-truth的IoU(Intersection-over-union)小于0.3视为negative(背景)
- 和任意的ground-truth的IoU大于0.7视为positive(前景)
- 不属于以上两种情况的proposal直接丢掉，不进行训练使用

regression是对proposal位置的修正

- 学习k个bounding-box-regressors
- 每个regresso负责一个scale和ratio的proposal，k个regressor之间不共享权值

## RPN Training ##

两种训练方式: joint training和alternating training
两种训练的方式都是在预先训练好的model上进行fine-tunning，比如使用VGG16、ZF等，对于新加的layer初始化使用random initiation，使用SGD和BP在caffe上进行训练
alternating training

首先训练RPN, 之后使用RPN产生的proposal来训练Fast-RCNN, 使用被Fast-RCNN tuned的网络初始化RPN,如此交替进行
joint training

首先产生region proposal,之后直接使用产生的proposal训练Faster-RCNN，对于BP过程,共享的层需要combine RPN loss和Faster-RCNN loss

## PERFORMANCE ##
![Alt Text](FasterRCNNResult.jpg)

repo_name: williamGD/Notes


text:
<file_sep>package controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import model.Document;

import utilities.CSVOutputGenerator;
import utilities.OutputGenerator;
import utilities.TagalogStemmer;
import utilities.TxtReader;
import view.IInvertedIndexView;

public class InvertedIndexController {

        private IInvertedIndexView view;
        private ArrayList<String> inputTokens;
        private ArrayList<String> documentData;
        private HashMap<String, ArrayList<Integer>> invertedIndex;
        private ArrayList<Integer> tempArrayList;
        private ArrayList<Document> detailedDocumentList;
        private TagalogStemmer stemmer;

        public InvertedIndexController(IInvertedIndexView view) {
                this.view = view;
                inputTokens = new ArrayList<>();
                documentData = new ArrayList<>();
                tempArrayList = new ArrayList<>();
                detailedDocumentList = new ArrayList<>();
                invertedIndex = new HashMap<String, ArrayList<Integer>>();
                stemmer = new TagalogStemmer();
        }

        public void constructInvertedIndex() {
        /** STEP 1 tokenize db? */
        /** STEP 2 tokenize input */
        /** STEP 3 save to inputTokens */
        /** STEP 4 search db for substring */
        /** STEP 5 save to invertedIndex */
        String input = view.getInput();

        /** tokenize the input*/
        inputTokens = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(input);
        while (st.hasMoreElements()) {
                inputTokens.add((String) st.nextElement());
        }
        /** stem inputs */
        inputTokens = stemmer.getStems(inputTokens);

        invertedIndex = new HashMap<String, ArrayList<Integer>>();
        /** add result to hashmap */
        for(int i = 0; i < inputTokens.size(); i++)
        {
            for(int j = 0; j < documentData.size(); j++)
            {
	            if(documentData.get(j).toLowerCase().contains(inputTokens.get(i).toLowerCase()))
	                tempArrayList.add(j+1);
            }
            invertedIndex.put(inputTokens.get(i), tempArrayList);
            tempArrayList = new ArrayList<>();
        }
        String combinedInput = "";
        /** add more to hashmap oyeh!! */
        for(int i = 0; i < inputTokens.size(); i++)
        {
        	combinedInput+= inputTokens.get(i) + " ";
        }
        combinedInput = combinedInput.trim();
        for(int j = 0; j < documentData.size(); j++)
        {
            if(documentData.get(j).toLowerCase().contains(combinedInput.toLowerCase()))
                tempArrayList.add(j+1);
        }
        invertedIndex.put(combinedInput, tempArrayList);
        tempArrayList = new ArrayList<>();

        boolean found = true;
        /** add more to hashmap hiwahiwalay!!! */
        for(int i = 0; i < documentData.size(); i++)
        {
        	for(String inputString: inputTokens) {
        		if(!(documentData.get(i).toLowerCase().contains(inputString.toLowerCase()))) {
        			found = false;
        			break;
        		}
        		else found = true;
        	}
        	if(found==true){
        		tempArrayList.add(i+1);
        	}
        }
        invertedIndex.put(combinedInput+" HIWAHIWALAY", tempArrayList);
        tempArrayList = new ArrayList<>();

        /** STEP 6 generate output */
        CSVOutputGenerator outputBuilder = new CSVOutputGenerator();
        OutputGenerator outputGenerator = new OutputGenerator(outputBuilder);
        outputGenerator.generateOutput(invertedIndex, "boolean results.csv");
        }

        public void constructInvertedIndex1(){
        /*STEP 1: tokenize and stem input**/
        /*STEP 2: place all data on ArrayList<Document> w/ score for each document is 0**/
        /*STEP 3: transverse through tokens and count the term frequency and update the score for each document**/
        /*STEP 4: arrange document by score**/
        /*STEP 5: place on csv file with name "ranked search activity 1.csv"**/
            String input = view.getInput();
            /*1**/
            inputTokens = new ArrayList<String>();
            StringTokenizer st = new StringTokenizer(input);
            while (st.hasMoreElements()) {
                    inputTokens.add((String) st.nextElement());
        }
            /** stem inputs */
            inputTokens = stemmer.getStems(inputTokens);
            invertedIndex = new HashMap<String, ArrayList<Integer>>();

            /*2**/
            for(int i = 0; i < documentData.size(); i++)
            {
            Document tempDocument = new Document(i+1, documentData.get(i), 0.00);
            detailedDocumentList.add(tempDocument);
            }
            /*3**/
            for(int i = 0; i < inputTokens.size(); i++)
            {
                for(int j = 0; j < detailedDocumentList.size(); j++ )
                {
               String str = detailedDocumentList.get(j).getContent().toLowerCase();
                Pattern p = Pattern.compile(inputTokens.get(i).toLowerCase());
                Matcher m = p.matcher(str);
                int frequency = 0;
                while (m.find()){
                    frequency += 1;
                }

                if(frequency == 0)
                    detailedDocumentList.get(j).setScore(detailedDocumentList.get(j).getScore()+(0.0)); //formula 1+ log(tf)
                else
                    detailedDocumentList.get(j).setScore(detailedDocumentList.get(j).getScore()+(1+Math.log10(frequency)));

                }

            }
            /*print score**/
               for(int j = 0; j < detailedDocumentList.size(); j++ )
                {
               System.out.println(j+1 +" Score = "+detailedDocumentList.get(j).getScore());

                }
            /*4**/
            Collections.sort(detailedDocumentList);
            Collections.reverse(detailedDocumentList);
            for(int i = 0; i< detailedDocumentList.size(); i++)
            {
            if(detailedDocumentList.get(i).getScore() == Double.valueOf(0))
                detailedDocumentList.remove(i);
                else
                {
                    tempArrayList.add(detailedDocumentList.get(i).getId());
                }
            }
            invertedIndex.put(input, tempArrayList);
            tempArrayList = new ArrayList<>();
            detailedDocumentList = new ArrayList<>();
            /*5**/
            CSVOutputGenerator outputBuilder = new CSVOutputGenerator();
            OutputGenerator outputGenerator = new OutputGenerator(outputBuilder);
            outputGenerator.generateOutput(invertedIndex, "ranked search activity 1.csv");
            }

        public void constructInvertedIndex2(){
            String input = view.getInput();
            /*1**/
            inputTokens = new ArrayList<String>();
            StringTokenizer st = new StringTokenizer(input);
            while (st.hasMoreElements()) {
                    inputTokens.add((String) st.nextElement());
        }
            /** stem inputs */
            inputTokens = stemmer.getStems(inputTokens);
            invertedIndex = new HashMap<String, ArrayList<Integer>>();

            /*2**/
            for(int i = 0; i < documentData.size(); i++)
            {
            Document tempDocument = new Document(i+1, documentData.get(i), 0.00);
            detailedDocumentList.add(tempDocument);
            }
            /*3**/
            for(int i = 0; i < inputTokens.size(); i++)
            {
                int df = getDocumentFrequency(inputTokens.get(i));
                for(int j = 0; j < detailedDocumentList.size(); j++ )
                {
               String str = detailedDocumentList.get(j).getContent().toLowerCase();
                Pattern p = Pattern.compile(inputTokens.get(i).toLowerCase());
                Matcher m = p.matcher(str);
                int frequency = 0;
                while (m.find()){
                    frequency += 1;
                }

                if(frequency == 0)
                    detailedDocumentList.get(j).setScore(detailedDocumentList.get(j).getScore()+(0.0*(Math.log10(303/df)))); // formula 1+log(tf)* log(N/df)
                else
                    detailedDocumentList.get(j).setScore(detailedDocumentList.get(j).getScore()+(1+Math.log10(frequency)*(Math.log10(303/df))));

                }

            }
            /*print score**/
               for(int j = 0; j < detailedDocumentList.size(); j++ )
                {
               System.out.println(j+1 +" Score = "+detailedDocumentList.get(j).getScore());

                }
            /*4**/
            Collections.sort(detailedDocumentList);
            Collections.reverse(detailedDocumentList);
            for(int i = 0; i< detailedDocumentList.size(); i++)
            {
            if(detailedDocumentList.get(i).getScore() == Double.valueOf(0))
                detailedDocumentList.remove(i);
                else
                {
                    tempArrayList.add(detailedDocumentList.get(i).getId());
                }
            }
            invertedIndex.put(input, tempArrayList);
            tempArrayList = new ArrayList<>();
            detailedDocumentList = new ArrayList<>();
            /*5**/
            CSVOutputGenerator outputBuilder = new CSVOutputGenerator();
            OutputGenerator outputGenerator = new OutputGenerator(outputBuilder);
            outputGenerator.generateOutput(invertedIndex, "ranked search activity 2.csv");

        }

        public void ReadTxtFiles()
        {
            TxtReader txtReader = new TxtReader();
            documentData = txtReader.getDocumentsList();
        }

        private int getDocumentFrequency(String token)
        {
            int df = 0;
                for(int j = 0; j < documentData.size(); j++)
                {
                        if(documentData.get(j).toLowerCase().contains(token.toLowerCase()))
                            df += 1;

                }
               return df;

        }

}
<file_sep>
package utilities;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 *
 * @author Kingston
 */
public class TxtReader
{
    private int numOfDocuments = 303;
    StringBuilder stringBuilder = new StringBuilder();
    ArrayList<String> documentsAL = new ArrayList<>();
    ArrayList<String> stopWordsAL =  new ArrayList<>();

    public TxtReader() {
    	for(int i = 0; i < numOfDocuments; i++) {
			try{
			  FileInputStream fstream = new FileInputStream("src/resources/Tagalog News - "+(i+1)+".txt");

			  DataInputStream in = new DataInputStream(fstream);
			  BufferedReader br = new BufferedReader(new InputStreamReader(in));
			  String strLine = "";

			  stringBuilder = new StringBuilder();
			  while ((strLine = br.readLine()) != null){
			      stringBuilder.append(strLine);
			  }
			  //Close the input stream
			  in.close();
			  String finalString = stringBuilder.toString();
			  documentsAL.add(finalString);

			  //System.out.println(finalString);
			  }catch (Exception e){//Catch exception if any
			    System.err.println("Error: " + e.getMessage());
			  }
    	}
    }

    public void readStopWords() {
                    try{
                      FileInputStream fstream = new FileInputStream("src/resources/fil-function-words.txt"); //"src/resources/fil-function-words.txt"

                      DataInputStream in = new DataInputStream(fstream);
                      BufferedReader br = new BufferedReader(new InputStreamReader(in));
                      String strLine;

                      while ((strLine = br.readLine()) != null){
                          stopWordsAL.add(strLine.trim());
                          //stringBuilder.append(strLine);
                      }
                      //Close the input stream
                      in.close();
                      //String finalString = stringBuilder.toString();
                      //stopWordsAL.add(finalString);

                      //System.out.println(finalString);
                      }catch (Exception e){//Catch exception if any
                        System.err.println("Error: " + e.getMessage());
                      }

}

    public ArrayList<String> getDocumentsList()
    {
    	return documentsAL;
    }

    public ArrayList<String> getStopWordsList()
    {
    	return stopWordsAL;
    }
}
<file_sep>package utilities;

import java.util.ArrayList;
import java.util.HashMap;

public abstract class OutputBuilder {

	abstract void generateOutput(String csvName);
	abstract void parseOutput(HashMap<String, ArrayList<Integer>> result);

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author Kingston
 */
public class Document implements Comparable <Document>
{
    private int id;
    private String content;
    private double score;

    public Document(int id, String content, double score)
    {
        this.id = id;
        this.content = content;
        this.score = score;
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getContent()
    {
        return content;
    }

    public void setContent(String content)
    {
        this.content = content;
    }

    public double getScore()
    {
        return score;
    }

    public void setScore(double score)
    {
        this.score = score;
    }

    @Override
    public int compareTo(Document that) {
        return Double.valueOf(this.score).compareTo(that.score);
    }
}

repo_language: Java

repo_name: kingstonkoa/InvertedIndex


text:
<repo_name>LdyOn/my_website<file_sep>/application/index/controller/Login.php
<?php
namespace  app\index\controller;
use think\Db;

use think\Cache;

class  Login  extends  \think\Controller{
	public  function  login(){
		$this->assign('name','');
		return $this->fetch("/login");
	}

}<file_sep>/application/index/model/Note.php
<?php
namespace   app\index\model;

use think\Model;

class Note  extends Model{

}<file_sep>/application/index/model/Admin.php
<?php
namespace   app\index\model;

use think\Model;

class Admin  extends Model{

}<file_sep>/application/index/controller/Edit.php
<?php
namespace  app\index\controller;
use think\Db;

use think\Cache;

class  Edit  extends  \think\Controller{

}<file_sep>/application/index/model/Article.php
<?php
namespace   app\index\model;

use think\Model;

class Article  extends Model{

}<file_sep>/application/index/model/User.php
<?php
namespace   app\index\model;

use think\Model;

class User  extends Model{

}<file_sep>/README.md
# my_website
This  is Ldy's  personal  website  developed  by  ldy.
It is  being  using  to  manage  personal  notes  and  articles.
<file_sep>/application/index/controller/Pages.php
<?php
namespace  app\index\controller;
use think\Db;

use think\Cache;

class  Pages  extends  \think\Controller{
    /*
     *显示页面
     * @auth LDY
     */
//主页
    public function index(){
   		$this->assign('data','');
    	$this->assign('name','main');
        return  $this->fetch('/main');
    }

//显示简介页
    public  function  introduction(){
    	$this->assign('name','introduction');
    	return  $this->fetch('/introduction');
    }

//显示笔记页
    public  function   note($id=1){
        $sql  = "select  title,id  from  note";
        $dir = Db::query($sql);
        $this->assign('dir',$dir);

        $content  = Db::table('note')->where('id',$id)->select();
        if(!empty($content)){
            $this->assign('title',$content[0]['title']);//文章标题
            $this->assign('content',htmlspecialchars_decode($content[0]['content']));
            //文章内容
            $this->assign('updatedTime',$content[0]['updated_at']);//更新时间
            $this->assign('createdTime',$content[0]['created_at']);//创建时间
        }

            $this->assign('name','note');
            return  $this->fetch('/note');
    }

//显示文章
    public  function   article($id=1){
        $sql  = "select  title,id  from  article";
    	$dir = Db::query($sql);
        $this->assign('dir',$dir);

        $content  = Db::table('article')->where('id',$id)->select();
        if(!empty($content)){
            $this->assign('title',$content[0]['title']);
            $this->assign('content',htmlspecialchars_decode($content[0]['content']));
            $this->assign('createdTime',$content[0]['created_at']);//创建时间
            $this->assign('updatedTime',$content[0]['updated_at']);
        }

        $this->assign('name','article');
    	return  $this->fetch('/article');
    }
}

<file_sep>/runtime/temp/c1e9294ea401303317d48e54fb52e1aa.php
<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:56:"D:\wamp64\www\thinkphp5/application/index\view\note.html";i:1502761403;s:56:"D:\wamp64\www\thinkphp5/application/index\view\main.html";i:1502332374;}*/ ?>
<!DOCTYPE html>

 	<title>流年居</title>
   <link rel="stylesheet" type="text/css" href="/public/static/css/main.css" />

日期 2017年8月7日

天气

登录

一个人看孤独的风景

流年谨の流年居

    			<a  href="/" style="<?php if($name == 'main'): ?>color:#0000FF<?php endif; ?>">
主页

    			<a  href="/index.php/introduction" style="<?php if($name == 'introduction'): ?>color:#0000FF<?php endif; ?>">
简介

    			<a  href="/index.php/article"  style="<?php if($name == 'article'): ?>color:#0000FF<?php endif; ?>">
散文

    			<a  href="/index.php/note"  style="<?php if($name == 'note'): ?>color:#0000FF<?php endif; ?>">
笔记

<?php if(is_array($dir) || $dir instanceof \think\Collection || $dir instanceof \think\Paginator): $i = 0; $__LIST__ = $dir;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
	<a  href="/index.php/article/<?php echo $vo['id']; ?>" <?php if($vo['title'] == $title): ?>style="color:#00FFFF"  onclick="disableLink(this);" <?php endif; ?>>
<?php echo $vo['title']; ?>

<?php endforeach; endif; else: echo "" ;endif; ?>

<?php if(!(empty($title) || (($title instanceof \think\Collection || $title instanceof \think\Paginator ) && $title->isEmpty()))): ?>

<?php echo $title; ?>

<?php echo $content; ?>

创建时间：<?php echo $createdTime; ?>

更新时间：<?php echo $updatedTime; ?>

<?php else: ?>

没有文章!

<?php endif; ?>

Powered  by  LDY
		Email:<EMAIL>

languages: Markdown PHP


text:
<file_sep>#!/usr/bin/env python3

import random as rn
import discord as ds
import sys

def moveOn(): # a simpe handler for stoping the program until user input is suplied
    exit=input()
    if exit != "":
        return True
    else:
        return False

Client=ds.Client()
@Client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@Client.event
async def on_message(message):
    if message.content.startwith("&&Yeet"):
        await message.channel.send("YEET")

Numbs={
    1:"Kelly's Eye",
    2:"One little duck || Me and you",
    3:"Cup of tea || You and me",
    4:"knock on the door",
    5:"Man alive",
    6:"Tom Mix || Half a Dozen",
    7:"Lucky",
    8:"Garden Gate",
    9:"Doctors Orders",
    10:"Boris's Den",
    11:"legs eleven",
    12:"A Dozen",
    13: "Unlucky for some",
    14:"The lawnmower",
    15:"Young and Keen",
    16:"Never been kissed",
    17:"P<NAME>",
    18:"Coming of age",
    19:"Goodbye Teens",
    20:"One score || Getting Plenty",
    21:"Key of the Door",
    22:"Two Little Ducks",
    23:"The lord is my shepard",
    24:"A double Dozen",
    25:"Duck and a Dive",
    26:"Two and six, half a crown || A to Z",
    27:"Duck and a Crutch",
    28:"In a State",
    29:"Rise and shine",
    30:"<NAME> || <NAME>",
    31:"Get up and run",
    32:"buckle my shoe",
    33:"All the Threes || Fish Chips and Peas",
    34:"Ask for more",
    35:"jump and jive",
    36:"triple dozen",
    37:"A lonely one",
    38:"Christmas cake",
    39:"steps",
    40:"Life Begins",
    41:"A lonely one",
    42:"A lonely one",
    43:"Down on your knees",
    44:"Droopy drawers",
    45:"Half way there",
    46:"Up to tricks",
    47:"A lonely one",
    48:"Four Dozen",
    49:"PC",
    50:"It's a bullseye! || Snow white",
    51:"A lonely one",
    52:"Chicken vindaloo || <NAME> || Deck of Cards",
    53:"Here comes Herbie",
    54:"Man at the Door",
    55:"All the fives",
    56:"shottes Bus",
    57:"Heinz Varieties",
    58:"A lonely one",
    59:"The brighton line",
    60:"Grandmas Getting Frisky",
    61:"A lonely one",
    62:"tickity boo",
    63:"Katie's bad knee",
    64:"Almost Retired",
    65:"Stop Working!",
    66:"Clickety click ||<NAME>",
    67:"Stairway to heaven",
    68:"Pick a mate",
    69:"Anyway up, Meal for Two, A Favourite of mine || NICE",
    70:"A lonely one",
    71:"Bang on a drum",
    72:"<NAME>",
    73:"Queen Bee. Under The Tree. Lucky 3",
    74:"Hit the floor",
    75:"A lonely one",
    76:"Trombones || Was she worth it?",
    77:"Two Little crutches || Sunset strip",
    78:"39 more steps",
    80:"Gandhi's Breakfast ",
    81:"fat lady with a walking stick",
    82:"I'm gonna get more right than you ",
    83:"Time for tea",
    84:"Seven Dozen",
    85:"Stayin Alive",
    86:"Between the sticks",
    87:"Torquay to devon",
    88:"two fat ladys",
    89:"Nearly There",
    90:"Top of the shop",
    91:"A lonely one",
    92:"A lonely one",
    93:"A lonely one",
    94:"A lonely one",
    95:"A lonely one",
    96:"A lonely one",
    97:"A lonely one",
    98:"A lonely one",
    99:"A lonely one",
    100:"A lonely one",
}
exi = False
while exi != True:
    if bool(Numbs) == False:
        break
    else:
        num = rn.choice(list(Numbs.keys())) ## selects a random key from the Numbs dictionary and putes it in num
        output = Numbs[num] +" "+ str(num)
        print(output)
        del Numbs[num]
        exi = moveOn()

sys.exit("we are finished now")
<file_sep>#+TITLE: Readme

* A simple discord bot to output bingo numbers and there corresponding Bingo terms
- that's it! it is meant to be used in a setting where bingo cards and a host already exist and the host need a good way to read numbers and output them to a discord channel
- it has been custom build for our [[https://utcr.live][radio show]] where we host a bingo night!
* Any issues or suggestions...
[[mailto:<EMAIL>][email me!]]

languages: Org Python

repo_language: Org

repo_name: benjisoft/Bingo-Bot


text:
<repo_name>AMAbhi/Binary-Search-1<file_sep>/binarysearchrotatearray.py
# Time Complexity : O(1)
# Space Complexity : O(lon n))
# Did this code successfully run on Leetcode : Yes
# Any problem you faced while coding this : No

# Your code here along with comments explaining your approach

class Solution:
    def search(self, nums: List[int], target: int) -> int:
        l=0 #lower bound
        u=len(nums)-1 #upper bound

        if not nums:
            return -1

        while l<=u:
            mid=(l+u)//2 #find mid value to find efficien process for search target element

            if target==nums[mid]:
                return mid

            if nums[l]<=nums[mid]:
                if nums[l]<=target<=nums[mid]:
                    u=mid-1
                else:
                    l=mid+1
            else:
                if nums[mid]<=target<=nums[u]:
                    l=mid+1
                else:
                    u=mid-1
        return -1

repo_language: Python