I have some SVG files that i want to combine into single file. I'm trying svg-net and library really can combine images but i can't to center images. Trying set X and Y for Children but X and Y are still 0 in result file.
var svgResult = new SvgDocument();
var svgBorder = SvgDocument.Open(borderFile);
svgBorder.X = 0;
svgBorder.Y = 0;
svgBorder.Overflow = SvgOverflow.Inherit;
svgBorder.AspectRatio = new Svg.SvgAspectRatio(SvgPreserveAspectRatio.xMidYMid);
svgResult.X = 0;
svgResult.Y = 0;
svgResult.Overflow = SvgOverflow.Inherit;
svgResult.AspectRatio = new Svg.SvgAspectRatio(SvgPreserveAspectRatio.xMidYMid);
svgResult.Children.Add(svgBorder);
for (var i = 0; i < fileNames.Count - 1; i++)
{
var svgPart = SvgDocument.Open(fileNames[i + 1].name);
svgPart.X = (svgBorder.Width / 2) - (svgPart.Width / 2);
svgPart.Y = (svgBorder.Height / 2) - (svgPart.Height / 2);
svgPart.Overflow = SvgOverflow.Inherit;
svgPart.AspectRatio = new Svg.SvgAspectRatio(SvgPreserveAspectRatio.xMidYMid);
svgResult.Children.Add(svgPart);
}
if (!File.Exists(svgResultPath))
svgResult.Write(svgResultPath);
What can i miss? Or maybe i'm using a wrong tool?
Related
I want to create a program that will create the picturebox to the number that the user enters.
I use the following code.
int i,j,X = 395, Y = 7, S = 200 / int.Parse(textBox2.Text), C = int.Parse(textBox2.Text),CCC = 0;
PPP = new PictureBox[C];
for (i = 0; i < C; i++)
{
X = X + 5;
for (j = 0; j < C; j++)
{
Y = Y + 5;
PPP[CCC] = new PictureBox()
{
BackColor = Color.OrangeRed,
Size = new Size(S, S),
Location = new Point(X, Y)
};
Controls.Add(PPP[CCC]);
}
CCC++;
}
Thanks.
Part of the problem is that you have to update X and Y so your PictureBoxes are not drawn on top of each other.
I've tried without luck do make such graph in WinForms with Chart control.Graph with uneven intervals on y axis My first idea was to use pointed Chart with images for empty and not empty marker. The lines are displayed, but unfortunatelly there is a big space between values 4 - 19 and 20 - 33. Is there a way to avoid the space when using standard WinForms chart Control?
My second idea was to use a DatagridView. I could add not more that something aboit 700 columns. I would need almost 2000 columns. Thus the DataGridView isn't best choice for me.
Thank for any hint how to achieve it.
Edit 1:
As sugested by TnTinMn I've tried ScaleBreakStyle. This seems to remove some spaces from the graph. At the moment my graph looks like this:
This was achieved by the Code:
var chartArea = chart1.ChartAreas[series.ChartArea];
chartArea.AxisX.LabelStyle.IsStaggered = false;
chartArea.AxisX.Minimum = 0;
chartArea.AxisX.Maximum = (int)numericUpDown1.Value;
chartArea.AxisX.IsReversed = true;
chartArea.AxisX.Interval = 1;
chartArea.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;
chartArea.AxisY.ScaleBreakStyle.Enabled = true;
chartArea.AxisY.ScaleBreakStyle.BreakLineStyle = BreakLineStyle.None;
chartArea.AxisY.ScaleBreakStyle.Spacing = 0;
chartArea.AxisY.ScaleBreakStyle.CollapsibleSpaceThreshold = 50;
chartArea.AxisY.Interval = 1;
If I try to put the y labels on the left side, it doesn't work
chartArea.AxisY.Enabled = AxisEnabled.False;
chartArea.AxisY2.Enabled = AxisEnabled.True;
Adding folowing code doesn't solve the problem:
chartArea.AxisY2.ScaleBreakStyle.Enabled = true;
chartArea.AxisY2.ScaleBreakStyle.BreakLineStyle = BreakLineStyle.None;
chartArea.AxisY2.ScaleBreakStyle.Spacing = 0;
chartArea.AxisY2.ScaleBreakStyle.CollapsibleSpaceThreshold = 50;
chartArea.AxisY2.Interval = 1;
How can I remove 26 and 28, and leave only 1 and 27 on the chart? How can I put 1 and 27 on the bottom and leave a "big" space above them?
Edit 2:
After some tryies I've achieved what I wanted(I still have to adjust the marker images, but it looks very promising).
This is what I have at the moment:
As TnTiMn said, it is a little bit tricky. I had to map 1, 2, 3... to my real values and then to assign custom labels. I didn't used ScaleBreakStyle. Thanks anyway for your help.
My code:
chart1.ChartAreas[0].AxisX.IsReversed = true;
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.False;
chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
chart1.ChartAreas[0].AxisY2.ScaleView.SizeType = DateTimeIntervalType.Number;
chart1.ChartAreas[0].AxisY2.MajorTickMark.Enabled = false;
chart1.Series[0].MarkerImage ="NotEmptyPoint.png";
chart1.Series[0].EmptyPointStyle.MarkerImage = "EmptyPoint.png";
chart1.Series[1].MarkerImage = "NotEmptyPoint.png";
chart1.Series[1].EmptyPointStyle.MarkerImage = "EmptyPoint.png";
chart1.Series[2].MarkerImage = "NotEmptyPoint.png";
chart1.Series[2].EmptyPointStyle.MarkerImage = "EmptyPoint.png";
chart1.ChartAreas[0].AxisY.Interval = 1;
chart1.ChartAreas[0].AxisY2.Interval = 1;
chart1.ChartAreas[0].AxisY2.Minimum = 0;
chart1.ChartAreas[0].AxisY2.Maximum = 10;
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 10;
int number = 0;
string mappedNumber;
for (int i = 1; i < 15; i++)
{
number = 1;
mappedNumber = "1";
chart1.Series["Series1"].Points.AddXY(i, number);
chart1.ChartAreas[0].AxisY2.CustomLabels.Add(number - 0.5, number + 0.5, mappedNumber);
if(i % 3 == 0)
{
chart1.Series["Series1"].Points[chart1.Series["Series1"].Points.Count - 1].IsEmpty = true;
}
}
for (int i = 1; i < 15; i++)
{
number = 2;
mappedNumber = "7";
chart1.Series["Series2"].Points.AddXY(i, number);
chart1.ChartAreas[0].AxisY2.CustomLabels.Add(number - 0.5, number + 0.5, mappedNumber);
if (i % 4 == 0)
{
chart1.Series["Series2"].Points[chart1.Series["Series2"].Points.Count - 1].IsEmpty = true;
}
}
for (int i = 1; i < 15; i++)
{
number = 3;
mappedNumber = "20";
chart1.Series["Series3"].Points.AddXY(i, number);
chart1.ChartAreas[0].AxisY2.CustomLabels.Add(number - 0.5, number + 0.5, mappedNumber);
if (i % 5 == 0)
{
chart1.Series["Series3"].Points[chart1.Series["Series3"].Points.Count - 1].IsEmpty = true;
}
}
Im new at programming, and I am trying to learn Encog 3.3 Library. I worked on making my first network. I was able to write and understand the Code; However, My error rate does not go below 0.79, I used TANH activation function. My network is suppose to return 1 of three values -1,0,1 based on a set of variables I input it. Has anyone Have this same Problem?
this is the Code:
static void Main(string[] args)
{
// creating the neural net : network
var network = new BasicNetwork();
network.AddLayer(new BasicLayer(null, true,21));
network.AddLayer(new BasicLayer( new ActivationTANH(), true,15));
network.AddLayer(new BasicLayer(new ActivationTANH(), true, 15));
network.AddLayer(new BasicLayer(new ActivationTANH(), true,1));
network.Structure.FinalizeStructure();
network.Reset();
// creating the training Data
string Path = "";
var listArray = GetFile(Path);
int amountNumbersY = GetYSize(listArray);
int amountNumbers = GetXSize(listArray[1]);
string[,] matrixString = new string[listArray.Length, amountNumbers]; matrixString = splitter(listArray, amountNumbers);
double[][] allData = new double[amountNumbers][];
for (int i = 0; i < allData.Length; i++)
allData[i] = new double[amountNumbersY];
allData = ConvertToDouble(matrixString, amountNumbers);
// creating the inpuit and output
double[][] XOR_INPUT = new double[amountNumbersY][];
for (int i = 0; i < amountNumbersY; i++)
{
XOR_INPUT[i] = new double[amountNumbers - 1];
}
double[][] XOR_IDEAL = new double[amountNumbersY][];
for (int i = 0; i < amountNumbersY; i++)
{
XOR_IDEAL[i] = new double[1];
}
XOR_INPUT = GetInput(allData, amountNumbers, amountNumbersY, 1);
XOR_IDEAL = GetIdealOutPut(allData, amountNumbers, amountNumbersY, 1);
// normalizing the Arrays
double[][] temp_Input = new double[amountNumbersY-1][];
for (int i = 0; i < amountNumbersY-1; i++) // initializing the x axis
{
temp_Input[i] = new double[amountNumbers - 1];
}
double[][] temp_Ideal = new double[amountNumbersY-1][]; // same as above for output matrix
for (int i = 0; i < amountNumbersY-1; i++)
{
temp_Ideal[i] = new double[1];
}
double[][] closedLoop_temp_Input = new double[amountNumbersY-1][];
for (int i = 0; i < amountNumbersY-1; i++) // initializing the x axis
{
closedLoop_temp_Input[i] = new double[amountNumbers - 1];
}
double[][] closedLoop_temp_Ideal = new double[amountNumbersY-1][];
for (int i = 0; i < amountNumbersY-1; i++)
{
closedLoop_temp_Ideal[i] = new double[1];
}
var hi = 1;
var lo = -1;
var norm = new NormalizeArray { NormalizedHigh = hi, NormalizedLow = lo };
for (int i = 0; i < amountNumbersY-1; i++)
{
temp_Input[i] = norm.Process( XOR_INPUT[i]);
}
closedLoop_temp_Input = EngineArray.ArrayCopy(temp_Input);
var Ideal_Stats = new NormalizedField(NormalizationAction.Normalize,"Temp_Ideal",1,-1,-1,1);
for (int i = 0; i < amountNumbersY - 1; i++)
{
temp_Ideal[i][0] = Ideal_Stats.Normalize(XOR_IDEAL[i][0]);
}
closedLoop_temp_Ideal = EngineArray.ArrayCopy(temp_Ideal);
IMLDataSet trainingSet = new BasicMLDataSet(closedLoop_temp_Input, closedLoop_temp_Ideal);
// training the network
IMLTrain train = new ResilientPropagation( network, trainingSet);
ICalculateScore score = new TrainingSetScore(trainingSet);
IMLTrain annealing = new NeuralSimulatedAnnealing(network,score,10,2,10);
int epoch = 1;
do
{
if (epoch == 50)
{
int i = 0;
do
{
annealing.Iteration();
Console.WriteLine("Annealing: " + i +", Error: " + annealing.Error);
i++;
} while (i < 5);
}
train.Iteration();
Console.WriteLine(#" Epoch: "+epoch+ #", Error: "+train.Error+"...");
epoch ++;
} while ( train.Error<0.01 || epoch < 1000);
// testing the network
}
}
}
The training rate not falling is one of the most common problems in machine learning. Often it is because the data given to the model simply does not support a prediction. You are training a neural network to predict an output given the input. Consider if you were to train on the following inputs and expected outputs. The data might be noisy or it might be contradictory.
A few suggestions. First, dump your training data to a file and have a look at it. Is it what you expect? Are all of the values between -1 and 1. You have quite a bit of code happening before the training. There could be something going wrong there.
You also have a somewhat hybrid training approach going on, with RPROP and annealing. Perhaps just stick to RPROP and see what happens.
How do I calculate or convert my quadpoints to a rectangle?
var quad = dic.Get(PdfName.QUADPOINTS) as PdfArray;
var rect = new iTextSharp.text.Rectangle(<missing conversion>);
var filter = new RegionTextRenderFilter(rect);
Well while waiting for an answer I found it myself. The Quadpoints array is always divisible by 8. A pair of x,y coordinates for each corner of the rectangle (2 * 4 = 8). With this information in mind I created the following extension method:
public static class Extensions
{
public static iTextSharp.text.Rectangle[] ToRectangle(this PdfArray quadricles)
{
var result = new List<iTextSharp.text.Rectangle>();
for (var m = 0; m < quadricles.Size; m += 8)
{
var dimX = new List<float>();
var dimY = new List<float>();
for (var n = 0; n < 8; n += 2)
{
var x = quadricles[m + n] as PdfNumber;
dimX.Add(x.FloatValue);
var y = quadricles[m + n + 1] as PdfNumber;
dimY.Add(y.FloatValue);
}
result.Add(new iTextSharp.text.Rectangle(dimX.Min(), dimY.Min(), dimX.Max(), dimY.Max(), 1));
}
return result.ToArray();
}
}
I have got this method to get a polynomial with my desired degree:
public static double[] Polyfit(double[] x, double[] y, int degree)
{
// Vandermonde matrix
var v = new DenseMatrix(x.Length, degree + 1);
for (int i = 0; i < v.RowCount; i++)
for (int j = 0; j <= degree; j++) v[i, j] = Math.Pow(x[i], j);
var yv = new DenseVector(y).ToColumnMatrix();
QR qr = v.QR();
// Math.Net doesn't have an "economy" QR, so:
// cut R short to square upper triangle, then recompute Q
var r = qr.R.SubMatrix(0, degree + 1, 0, degree + 1);
var q = v.Multiply(r.Inverse());
var p = r.Inverse().Multiply(q.TransposeThisAndMultiply(yv));
Console.WriteLine(p.Column(0).ToString());
return p.Column(0).ToArray();
}
How can I feed the method above with values from my chart (x and y)?
chart.Series[0].Points.... ?
I think you need this:
chart1.Series[0].YValueMembers
chart1.Series[0].XValueMember
The Points property is a getter, so you cannot set a new instance of DataPointCollection to it. You should however be able to access methods on the current DataPointCollection.
You could try something along the lines of:
chart.Series[0].Points.AddXY(double, double)
You would then iterate the array(s) and set the points manually.
MSDN DataPointCollection for more information.
A working solution is:
////generate polynomial of degree 4 fiting to the points
double[] arrayX = new double[chart.Series[0].Points.Count()];
double[] arrayY = new double[chart.Series[0].Points.Count()];
double[] arrayResult = { };
for (int i = 0; i < chart.Series[0].Points.Count(); i++)
{
arrayX[i] = chart.Series[0].Points[i].XValue;
arrayY[i] = chart.Series[0].Points[i].YValues[0];
}
arrayResult = Polyfit(arrayX, arrayY, 4);
foreach (double element in arrayResult)
{
MessageBox.Show(element.ToString());
}
double functionVarE = arrayResult[0];
double functionVarD = arrayResult[1];
double functionVarC = arrayResult[2];
double functionVarB = arrayResult[3];
double functionVarA = arrayResult[4];
double equationVar = 0;
//prepare the function series in the graph
if (chart.Series.IndexOf("function") < 0)
chart.Series.Add("function");
chart.Series[2].Points.Clear();
chart.Series[2].ChartType = SeriesChartType.Line;
for (int x = -500; x < 1000; x++) //hardcoding
{
equationVar = functionVarA * (Math.Pow(x, 4)) + functionVarB * (Math.Pow(x, 3)) + functionVarC * (Math.Pow(x, 2)) + functionVarD * x + functionVarE;
chart.Series[2].Points.AddXY(Convert.ToDouble(x), equationVar);
}
This is a working solution I coded. If you see any improvement feel free to tell me!